This works on Greasemonkey, but I don't know why it doesn't work on Scriptish:
// ==UserScript==
// #name myscript
// #namespace xxx
// #include http://*
// #version 1
// #grant GM_getResourceText
// #resource resourceName http://xxx.xxx/style.css
// ==/UserScript==
alert(GM_getResourceText('resourceName'))
The css file is actually downloaded, and console log says [myscript] not defined.
This has come up since Firefox update to version 30. Try to "enable #grant" in the settings of Scriptish. If you don't find this setting in your Scriptish options dialog, go to URL about:config and find the key extensions.scriptish.enableScriptGrant. If that doesn't work, go to scriptish download page and list all available versions. Version 0.1.12 works well with Firefox 30. Official latest version is 0.1.11.
Related
So I frequent a webpage which uses ouo.io to try and make some advertisement money on links. Lucky me that that particular redirector-service doesnt alter or hide the original url in any way, so I was thinking that perhaps it would be possible (with a tamper/greasemonkey script I guess) to remove the ouo part from the urls automatically
The urls are like this
https:// ouo.io/qs/pRqHNWPK?s=https://destination.url/
(The space between the protocol and the ouo part was intentional because without it this link trips the URL-shortener warning thus not letting me post)
Anybody who has a tampermonkey script that would be adaptable for this situation? I tried messing around and writing something myself but that didn't work (or do anything at all lmao).
Here is a sample code to show you how it can be done ...
(remove extra space added before ouo)
Redirecting based on location.href of the new page
// ==UserScript==
// #name Remove Redirect
// #match https:// ouo.io/qs/*
// #grant none
// #version 1.0
// run-at document-start
// ==/UserScript==
const redirect = location.search.match(/http.+/); // find redirect URL
if (redirect) {
window.stop(); // stop loading the page
location.href = decodeURIComponent(redirect[0]);
}
You can also change the links on the pages. It is much more resource intensive since it has to run on every page thus not recommended. Here is an example ...
// ==UserScript==
// #name Remove Redirect Link
// #match *://*/*
// #grant none
// #version 1.0
// ==/UserScript==
document.querySelectorAll('a[href^="https:// ouo.io/qs/"]').forEach(item => {
const redirect = item.search.match(/http.+/); // find redirect URL
if (redirect) {
item.href = decodeURIComponent(redirect[0]);
}
}):
While reviewing the code with gitlab merge request web page, tabulation is 8 spaces.
It makes the code difficult to read. How could I move it to 1 or 2 spaces ?
It seems to be impossible to achieve that by available GitLab settings, but this can be hacked using Greasemonkey/Tampermonkey browser extension:
// ==UserScript==
// #name Custom tab-width
// #version 1
// #grant none
// #include https://your.gitlab.server.com/*/diffs*
// ==/UserScript==
var style = document.createElement("style");
style.type = "text/css";
style.innerHTML = "span.line {tab-size:2; -moz-tab-size:2;}";
document.head.appendChild(style);
or by any other stylish-like extensions which allow you to attach any custom css rules to web pages:
span.line {tab-size:2; -moz-tab-size:2;}
See this huge identations is painful (for me). Is there a way to set tab size to 4 spaces.
This picture is taken from local Gitlab CE server with minimal customization. I think tabsize 8 spaces is default.
Go to Settings -> Preferences -> Behavior and set Tab width
Yeah, gitlab uses browser CSS property tab-size which default value is 8.
There's a bug discussion about this here:
https://gitlab.com/gitlab-org/gitlab-ce/issues/2479
You can change gitlab CSS and you'll have what you want.
As of February 2021, this has not been addressed. One can check the current GitLab issue for progress, but in the meantime, this comment on the thread offers a solution via creating a UserScript via Greasemonkey / Tampermonkey with this script:
// ==UserScript==
// #name GitLab Tab Size
// #version 1
// #include https://gitlab.com/*
// #grant none
// ==/UserScript==
const TAB_SIZE = 2
window.addEventListener('load', function() {
const styleElement = document.createElement('style')
styleElement.innerHTML = `
.diff-content, pre.code {
-moz-tab-size: ${TAB_SIZE};
tab-size: ${TAB_SIZE};
}
`
document.head.appendChild(styleElement)
})
Credit to Brendan Gadd from that thread.
I would like to change a page using a Greasemonkey script, but the page is the result of a CGI POST call and thus the URL looks like this:
http://www.example.com/cgi-bin/foo.pl
So obviously I cannot use the #include in the Greasemonkey script, because that URL fits a lot of pages the app can generate.
I could just look for some elements on the page within the script before doing stuff:
if (document.getElementById('someIdentifier')) {
// do changes in here
}
But I was wondering if there is a better, maybe built-in way to do this.
Greasemonkey (and most userscript engines) has no built-in way to target a page by its elements. Your script needs to poll or use mechanisms like Mutation Observers to check for the desired elements.
A handy way to do this is to use the waitForKeyElements() utility, and you still want to use the #include, #exclude, and/or #match directives to narrow down the page firings as much as possible.
Here is a complete Greasemonkey/Tampermonkey script illustrating the process:
// ==UserScript==
// #name _Do something after select posts
// #include http://www.example.com/cgi-bin/foo.pl*
// #require http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js
// #require https://gist.github.com/raw/2625891/waitForKeyElements.js
// #grant GM_addStyle
// ==/UserScript==
/*- The #grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
function processTargetElement (jNode) {
//***** YOUR CODE HERE *****
jNode.css ("background", "pink");
}
waitForKeyElements ("#someIdentifier", processTargetElement);
I have a simple Greasemonkey script:
// ==UserScript==
// #name hello
// #namespace http://www.webmonkey.com
// #description A test of accessing documents using file:// protocol
// #include http* file*
// #grant none
// ==/UserScript==
alert("hi");
It works fine as long as the URL is of the form http://... How do I also get the script to run on URLs of the form file://...?
In the User Settings section I have http://* and file://* as the included pages and in the Script Settings section I have http* file* in the "Included Pages" box.
See "Greaseable schemes" in the Greasemonkey docs. Greasemonkey ignores the file:// protocol by default.
For scripts to work with file:// paths, you need to open about:config and set extensions.greasemonkey.fileIsGreaseable to true.
You might possibly have to restart Firefox for this setting to take effect.
Also, // #include http* file* is invalid syntax. You would use:
// #include http://*
// #include https://*
// #include file://*
except, avoid using such global includes as much as you can. Tune to the script to just the domain(s) and/or page(s) you explicitly target.
This: avoids unexpected side effects, increases performance, and reduces the chances of being pwned by some "zero day" exploit.
I also recommend that you delete the User Settings options for scripts you write yourself. This will only lead to heartache and confusion later. ;) Use the metadata section of the script, only, for scripts you control.