Putting Javascript Before URL? Another Solution?

I’m trying to determine if it would be possible to prepend a
javascript in front of a URL. Let me explain:

About five years ago I discovered a website called Lingro. lingrodotcom/ It’s a language translation website. I live in El Salvador, Central America and so was using the site with a Spanish-language newspaper here to help me learn Spanish.
lapaginadotcom.sv/ I use a Chromebox to access the internet.

Everything was fine for the first few years, but later La Pagina started loading extremely slowly when used with Lingro. It is impossible to use now. See here:
lingrodotcom/translate[can’t post full URL]www.lapaginadotcom.sv/

I had been in contact with the creator of Lingro for a number of
years, Artur Janc. In my recent communication with him, he suggested
that I use his “quick lingro lookup!” javascript bookmarklet to solve the
problem. And it did. The problem is that it requires me to click the
bookmarklet for every article/link in the newspaper. See here:
https://lingro.com/docs/browser-tools.html . The javascript for
quick lingro lookup! is:
‘= ‘https://lingro.com/resources-api.js’); void(headID.appendChild(newScript))}’

So I’m wondering if it would be possible to put the javascript before Lingro’s URL so that I am able to click on any link in La Pagina without having to click the quick lingro lookup! javascript bookmarklet (that I have at the top of my browser) for each article in the newspaper? If not, can someone suggest something else to try? Steve

You might be able to make a userscript, using something like tampermonkey.


I wrote to the owner of Tampermonkey a few days ago to see if if he could help me with this issue. No reply yet. I do use a couple of userscripts on tampermonkey on a daily basis. I have no idea how to write a userscript myself, though. Tampermonkey relies on donations, so I did offer $10-$15 if he could help. Maybe it wasn’t enough.

I was thinking that it might be necessary to write, or pay someone to write, a userscript. But that work may have already been done. The Lingro website has a bookmarklet in javascript. Could it be imported, as written, into Tampermonkey? If you click the following link, and scroll down to where it says “quick lingro lookup!”, that is the javascript. https://lingro.com/docs/browser-tools.html Is javascript and userscript the same thing? Or does javascript need to be converted into userscript first in order to use it on Tampermonkey? Thanks.

This seems to work.

// ==UserScript==
// @name         lingro for lapagina
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  inject lingro script on lapagina pages
// @author       lasjorg
// @include      https://www.lapagina.com.sv/*
// @grant none
// @run-at document-start
// ==/UserScript==

(function() {
    setTimeout(() => {
      window.lingro_light_bookmarklet = true;
      const head = document.getElementsByTagName('head')[0];
      const script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = 'https://lingro.com/resources-api.js';
    }, 2000)

I had to add a pretty long timeout because of some issue which I believe is caused by Rocket Loader.

1 Like

I was thinking userscripts are like 10,000 lines of code. That’s pretty short. Are all userscripts about that length? I’ll have to take a look at tampermonkey to see what to do next. Maybe I can just cut/copy/paste it.

This link says that the process is 1) add userscript to userscriptdotorg, 2) install on tampermonkey. https://ooiks.com/2013/05/26/install-uninstall-user-script-in-google-chrome-through-tampermonkey-extension/ I searched for lasjorg on userscriptdotorg, but I don’t see anything. Have you ever added a script to userscriptdotorg?

To use it, just install tampermonkey. Then click the extension icon and select “Create a new script”. Paste in the code and save. Now when you go to the site it will auto load on every page.

The length of a script will depend on the functionality but most are fairly short and no I have not uploaded any scripts.

1 Like

Many thanks. I’ll do that. I don’t know how to repay you. This was very important to me. The creator of Lingro could have done this. He’s a developer. He’s in that line of work. I contacted him by e-mail and twitter about this userscript solution but he never responded. I guess he’s given up on maintaining the site.

Hi. I tried modifying your script to use with another newspaper, La Prensa Grafica, but I can’t get it to work. Do you know what the problem is? In the original script, I just substituted la prensa grafica for la pagina. https: // www. laprensagrafica. com (not able to post normal link)

La Pagina is working great!

It seems to work for me. Just replace the URL in the @include. Remember to use /* at the end to have it match on all.

// @include https://www.laprensagrafica.com/*

Thanks. I’m just reading your reply now. I never received an e-mail, so I assumed my message hadn’t been replied to. It turns out what I failed to do was to add the URL as an additional “specific site” on the Tampermonkey extension. I will be able to use your script with other sites now. Many thanks!

I ran into a problem. It was my fault. I recently bought a new Chromebox 3 to replace an older Chromebox. When I logged into the new one, all the extensions and the other settings were populated on to it. Afterwards, I noticed that a sideloaded extension was missing ans well as a Chrome Store extension that was no longer available through Google. After spending some time trying to re-sideload the missing extension, it loaded. But, I mistakenly loaded an older version. So I deleted it and tried re-loading the latest version, without success.

While in Developer Mode, I clicked update. I didn’t notice any adverse effect until I went to use Lingro using the script that you wrote. When I went into Tampermonkey settings, I noticed that the account was blank. Everything was working fine earlier in the day. So I re-entered the script that you wrote on to Tampermonkey once again, both for La Pagina and La Prensa Grafica. The problem is that the translation is now English to English! Before, when I would click the word casa, the translation would show as house. Now, it says “our english to english dictionary doesn’t have the word casa yet”. It shows a picture of a British flag >British flag. It should be Spanish flag>British flag. I have no idea how to resolve this issue. I went to my Lingro page, logged in, but didn’t see any way to make an adjustment.

When I plugged in my old Chromebox, everything was like it was before. Nothing had been deleted. Both newspapers show a Spanish flag>British flag in the upper left corner after clicking a word. Using the new Chromebox, it shows British flag>British flag after clicking a word.

An added couple of datapoints. So I turned off the Tampermonkey extension on the old and the new Chromebox. When I went to a Spanish language website using the old Chromebox, and then double-clicked the “quick lingro lookup!” bookmarklet at the top of my browser [this bookmarklet is what you had incorporated into the userscript, and appears to be the only one available from Lingro], each word that I clicked on the page was translated from Spanish to English. That device can’t be updated beyond Chrome OS Version 76.0.3809.136 (Official Build) (64-bit).

When I went to a Spanish language website using the new Chromebox, and then double-clicked the “quick lingro lookup!” bookmarklet at the top of the browser, each word that I clicked on the page could only be translated from English to English. The current build on the new device is Chrome OS Version 87.0.4280.88 (Official Build) (64-bit).

I need to change the default language translation in an online language translation Javascript from English to English to Spanish to English. The default had been Spanish to English, and it still is on an older Chromebox that I have that can’t be updated any further. After updating the Chrome build on my newer Chromebox to the latest build, the default is showing as English to English. The short script that I currently have and use on the older Chromebox was created for me with the help of a user on this forum.

The administrators of this forum think what I am writing is spam. I’m just looking for help to solve a problem that I have. It has to do with a language translation website that I use called Lingro. I don’t own the site and am not promoting it. I’ll try and follow-up with the URL of the “webmaster tools” of the website. The owner of the website is an employee of Google. The problem is that he is no longer maintaining the website. This has forced me to look for a script that will make the website functional once again.

As I mentioned, a script that was written for me was working fine for about a year until I bought a new Chromebox. Now, the default language translation is English to English. I don’t know how to change it. The “webmaster tools” URL says: “To explicitly specify the language to which text will be translated, you can set the dictionary attribute. For example, to make all words use the Spanish to German dictionary, your HTML would look like:…”

When I attempt to post the URL, I get the message: Sorry you cannot post a link to that host.

Here is the original freecodecamp link from last year which shows the script that was created for me. I need to alter that script somehow to allow for a Spanish to English default. Putting Javascript Before URL? Another Solution?

most of your posts had links to the same websites, so the system automatically flagged it as spam .

I guess I’ll have to avoid posting links for fear they’ll be misconstrued as spam, eh. So I won’t post the link to the following, but I believe it’s the solution to the problem that I have. It says:

“To explicitly specify the language to which text will be translated, you can set the dictionary attribute. For example, to make all words use the Spanish to English dictionary, your HTML would look like:”

Traducimos esta frase a inglés.

How do I incorporate that snippet of script into the script written by lasjorg?

Edit: Ridiculous. I’m blocked from posting a snippet of script, when lasjorg posted a script that he wrote for me! More spam, eh.