Greasy Fork is available in English.

Обсуждения » Разработка

Open Multi Links + button

hi, i should fix a script that doesn't work for me. I would like to open several sites simultaneously by pressing the "OPEN LINKS" button. The button appears but nothing happens when I click on it. Can you help me understand the problem? thank you so much

// ==UserScript==
// @name Link Opener
// @description Opens links when the button on the top right of each page is clicked.
// @include *
// ==/UserScript==

// Add new links here.
var links = [
'http://www.google.com',
'http://example.com'
];

// Don't touch below here
var e = document.createElement('button');
e.textContent = 'Open Links';
e.setAttribute('style', 'position: fixed !important; top: 0 !important; right: 0 !important;');
e.addEventListener('click', function() {
for (var i = 0; i < links.length; i++) {
GM_openInTab(links[i]);
}
}, false);
document.body.appendChild(e);

§
Создано: 13.01.2021
Отредактировано: 13.01.2021

GM_openInTab is not defined

Fixed version below


// ==UserScript==
// @name Link Opener
// @description Opens links when the button on the top right of each page is clicked.
// @include *
// @grant GM_openInTab
// ==/UserScript==

// Add new links here.
var links = [
'http://www.google.com',
'http://example.com'
];

// Don't touch below here
var e = document.createElement('button');
e.textContent = 'Open Links';
e.setAttribute('style', 'position: fixed !important; top: 0 !important; right: 0 !important;');
e.addEventListener('click', function() {
for (var i = 0; i < links.length; i++) {
GM_openInTab(links[i]);
}
}, false);
document.body.appendChild(e);

§
Создано: 16.01.2021
Отредактировано: 16.01.2021
GM_openInTab is not defined

Fixed version below


// ==UserScript==
// @name Link Opener
// @description Opens links when the button on the top right of each page is clicked.
// @include *
// @grant GM_openInTab
// ==/UserScript==

// Add new links here.
var links = [
'http://www.google.com',
'http://example.com'
];

// Don't touch below here
var e = document.createElement('button');
e.textContent = 'Open Links';
e.setAttribute('style', 'position: fixed !important; top: 0 !important; right: 0 !important;');
e.addEventListener('click', function() {
for (var i = 0; i < links.length; i++) {
GM_openInTab(links[i]);
}
}, false);
document.body.appendChild(e);

thank you a lot but it doesn't work... i'm trying it :( when i click on button, it happens nothing
anyway the two codes look identical, aren't they?

§
Создано: 16.01.2021
Отредактировано: 16.01.2021

the two codes look identical, aren't they

Difference is:

// ==UserScript==
// @grant GM_openInTab
// ==/UserScript==

doesn't work

Works in Chrome with Tampermonkey. What is your setup? What errors in a console?

§
Создано: 16.01.2021
Отредактировано: 16.01.2021

The two codes look identical but they are not identical, I've added 1 single line to the script, as Konf said.

The script works in Opera Browser With Tampermonkey.

Please answer what Konf asked you...

thank you for your avaibitliy. I'm using Greasemonkey (Firefox)

§
Создано: 17.01.2021
Отредактировано: 17.01.2021
thank you for your avaibitliy. I'm using Greasemonkey (Firefox)

What errors do you see in the browser dev console?

Install tampermonkey on your firefox and try using the script on tampermonkey.

Good morning! So, on greasemonkey there is no error, I just click on the 'open links' button but nothing happens. The click fails, as if the button were empty.

your script works with Tapermonkey, but not with Greasemonkey.
The problem is that on Tapermonkey it doesn't do what I want: my aim is to open a set of websites from the container it is in. With tapermonkey opens all websites but they are 'container-free'. While with Greasemonkey (setting a single website in the script, it works) opens the website perfectly within the same container.

What is container?

§
Создано: 18.01.2021
Отредактировано: 18.01.2021

This still doesn't make any sense because we don't know what you want to do.

There are "3 types of storage" on tampermonkey, localstorage, storage in the tampermonkey itself (gmset), no storage at all (var).

Just use one of these, I'm almost sure that they will meet your expectatives and do what you want.

Tampermonkey can (or not) keep your settings (the variables you change) during a private natigation, you could just use a private window to do what you want, and set tampermonkey to keep the changes permanent or not while using a private window in the extension settings. I guess that this is what you want...

To solve I would just like to run the script with Greasemonkey. There is not much to understand about the purpose and the modalities.

Ответить

Войдите, чтобы ответить.