Dyskusje » Propozycje stworzenia skryptu/stylu
Help with small script :)
Userscript cannot add items to the context menu. The only way would be to display a small icon on hover so that when you click that icon it will open that url.
I thought so at first, but Google showed results stating that it is possible:
http://stackoverflow.com/questions/6017187/userscript-add-item-to-right-click-menu
http://stackoverflow.com/questions/12315607/when-can-cant-my-userscript-trigger-a-right-click-context-menu-in-javascript
https://groups.google.com/forum/#!topic/greasemonkey-users/3VRywrs8LFY
Wow, another cool new feature of html5! And Firefox is pioneering the uncharted territory yet again.
// ==UserScript==
// @name instapaper context menu
// @grant GM_openInTab
// ==/UserScript==
var menu = document.body.appendChild(document.createElement('menu'));
menu.id = 'instapaper-context-menu';
menu.type = 'context';
menu.innerHTML = '<menuitem label="instapaper" icon="https://staticinstapaper.s3.amazonaws.com/images/favicon.png"></menuitem>';
menu.firstElementChild.addEventListener('click', function() {
GM_openInTab('http://www.instapaper.com/text?u=' + encodeURIComponent(menu.url));
});
document.body.addEventListener('contextmenu', function(e) {
menu.url = e.target.href;
document.body.setAttribute('contextmenu', menu.url ? menu.id : null);
});
Hi I tried to run your script but it gives me this error:
Exception: TypeError: document.body is undefined
@Scratchpad/2:5:5
WCA_evalWithDebugger@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:1164:16
WCA_onEvaluateJS@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:786:20
WCA_onEvaluateJSAsync@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/actors/webconsole.js:757:20
DSC_onPacket@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/server/main.js:1422:15
LocalDebuggerTransport.prototype.send/<@resource://gre/modules/devtools/dbg-client.jsm -> resource://gre/modules/devtools/transport/transport.js:545:11
makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/DevToolsUtils.js:82:14
makeInfallible/<@resource://gre/modules/commonjs/toolkit/loader.js -> resource://gre/modules/devtools/DevToolsUtils.js:82:14
cmd_showItemPreferences_doCommand@chrome://mozapps/content/extensions/extensions.js:1075:9
gVC_doCommand@chrome://mozapps/content/extensions/extensions.js:1377:5
showPreferences@chrome://mozapps/content/extensions/extensions.xml:1562:11
oncommand@about:addons:1:1
*/
What is your Greasemonkey version?
What site(s)?
I tried this site and few others, and Greasemonkey is latest version.......
Using Greasemonkey 3.1 I've installed this script and had no such problem. Try adding // @run-at document-end
on a new line before // ==/UserScript==
Well for some reason it simply doesn't show anything.... But thanks for help anyways!
What element do you right click? The script adds the instapaper item only to links because it's the way I've interpreted [current URL]
in your post.
I feel really stupid. Sorry your script works fine, but could you make it for current tab, not links? Thanks :)
// ==UserScript==
// @name Instapaper context menu
// @grant GM_openInTab
// ==/UserScript==
var menu = document.body.appendChild(document.createElement('menu'));
menu.id = 'instapaper-context-menu';
menu.type = 'context';
menu.innerHTML = '<menuitem label="Read on Instapaper" icon="https://staticinstapaper.s3.amazonaws.com/images/favicon.png"></menuitem>';
menu.firstElementChild.addEventListener('click', function() {
GM_openInTab('http://www.instapaper.com/text?u=' + encodeURIComponent(location.href));
});
document.body.setAttribute('contextmenu', menu.id);
Thanks your script works great, if I don't use context menu editor like:
https://addons.mozilla.org/en-US/firefox/addon/s3menu-wizard/?src=search
http://menueditor.mozdev.org/
Is there way to make this work with them?
P.S And it only works if I allow site with noscript.........
Well, this is a script so naturally it's affected by NoScript but the addon has many options and maybe you can find a way to whitelist the script. Also try Menu Filter addon, maybe it's more compatible. Anyway there's nothing that I can do about the issue. If nothing helps, your only option is to use an addon like Custom Buttons to create a custom toolbar button or keyconfig to create a hotkey with the script code. You can also try notifying the developers of NoScript and Menu Wizard of the problem.
Well menu filter works fine. As for noscript - I have no idea how to allow this script, it doesn't show on sites allowed......
BTW I'm using uBlock instead of NoScript, it's more than enough for my needs.
uBlock is ad blocker or it also block scripts as in NoScript?
Yes, in the advanced mode.
Help with small script :)
Hi, anyone could help me make this script:
Contextmenu entry that opens in current tab this - "http://www.instapaper.com/text?u=[current URL]"
Thanks! :D