How load a local CSS file to specific site - userscripts

I'm looking for a way to make the function GM_addStyle add CSS straight from the #resource on my local drive (I use macOS). My goal is to speed up the development of this CSS file.
Right now I'm copy&pasting changes to Tampermonkey > saving the userstyle & reloading the page.
Not working:
// ==UserScript==
// #name my style
// #version 0.1
// #description a few friendliness tweaks
// #author thomas
// #match http://stackoverflow.com/*
// #resource my_style file:///Users/thomas/style.css
// #grant GM_addStyle
// ==/UserScript==
(function() { 'use strict'; GM_addStyle(GM_getResourceText('my_style')); })();
Thanks

Related

Replacing an extension-less image in gmail HTML view with tampermonkey

On HTML gmail view top left corner the new Gmail logo could be seen. I want to replace it with the old one ( https://i.imgur.com/kAQfeoj.png ) but I'm not sure how. I've tried a 9 year old stackoverflow thread but it didn't work since the gmail logo link isn't a link to the file with an extension.
found a way
// ==UserScript==
// #name Image Replacer
// #version 1.1
// #description Image Replacer
// #require http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// #match https://www.pinterest.com/pin/*
// #grant none
// ==/UserScript==
/*globals $*/
var old_url = "https://ci6.googleusercontent.com/proxy/WQ_JO_iFWK3AKuIPeHz_fnMMOaGLG0HAsCJWOkWiRo9Oa_NHUeQYCdmJEfw8llIVJ8fMP1mriJ81iPzrebHtesFsF7VIDS0QKCFmqu_RMT_-ow=s0-d-e1-ft"
var new_url = "https://i.imgur.com/kAQfeoj.png"
$(document).ready(function(){
$("img[src='"+old_url+"']").attr("src", new_url);
});

Is there a way to allow Tampermonkey to run on the chrome homepage?

I am trying to make an extension using the right click menu. I noticed that the menu didn't display on the Chrome homepage because Tampermonkey didn't run on it. This is my current code:
// ==UserScript==
// #name Go to Website.Net
// #namespace http://tampermonkey.net/
// #description Context menu to execute UserScript
// #version 0.1
// #author author
// #include *
// #grant GM_openInTab
// #run-at context-menu
// ==/UserScript==]
(function() {
'use strict';
GM_openInTab("https://website.net");
})();
Is there a way to allow Tampermonkey to run on the chrome homepage?

Why does a tampermonkey script for https://news.google.com/* appear in the menu for https://www.nytimes.com/?

I have a tampermonkey script with this header:
// ==UserScript==
// #name Google News - Remove old articles
// #namespace http://tampermonkey.net/
// #version 0.2
// #description Remove articles that already appeared recently
// #author AC
// #require http://code.jquery.com/jquery-latest.js
// #match https://news.google.com/*
// #icon https://www.google.com/s2/favicons?domain=google.com
// #grant none
// ==/UserScript==
When I am on the page https://www.nytimes.com/ and I click on the tampermonkey icon in the Firefox toolbar, this script appears. Why?
Because the page contains an iframe, and that iframe links to news.google.com:
Userscripts run in iframes, and when they do, they get added to the Tampermonkey icon at the top.

How Do I Make A Tampermonkey Userscript Replace Words In Text Files?

6 years ago I asked a question about rewriting text files displayed in a browser using greasemonkey.
Can I Make Greasmonkey Scripts Run On Text Files?
I am now coming back to a similar problem and I tried to paste it in to Tampermonkey but it doesn't replace the text.
What am I doing wrong here?
// ==UserScript==
// #name Rewrite LLVM License
// #namespace http://tampermonkey.net/
// #version 0.1
// #match http://llvm.org/releases/2.8/*
// #include http://llvm.org/releases/2.8/LICENSE.TXT
// #require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// #grant none
// ==/UserScript==
(function() {
//Just to tell the linter that $ is defined in jquery
/* global $ */
//Browsers display text in a pre tag
var pageTextNd=$("body > pre");
//Replace the text LLVM
var newPageTxt=pageTextNd.text().replace("LLVM", "Ernst Blofeld");
//Rewrite the page
pageTextNd.text(newPageTxt);
})();
It looks like the page you're interested in redirects to:
https://releases.llvm.org/2.8/LICENSE.TXT
so that's what you need to set your #include or #match to.
You also want to replace all instances of LLVM, so use .replaceAll:
// ==UserScript==
// #name Rewrite LLVM License
// #include https://releases.llvm.org/2.8/LICENSE.TXT
// #require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// #grant none
// ==/UserScript==
(function() {
//Just to tell the linter that $ is defined in jquery
/* global $ */
//Browsers display text in a pre tag
var pageTextNd=$("body > pre");
//Replace the text LLVM
var newPageTxt=pageTextNd.text().replaceAll("LLVM", "Ernst Blofeld");
//Rewrite the page
pageTextNd.text(newPageTxt);
})();
If you don't want to rely on replaceAll, use a regular expression with .replace instead: /LLVM/g.
It seems quite strange to rely on jQuery for something this trivial though - you can very easily accomplish this without a library:
// ==UserScript==
// #name Rewrite LLVM License
// #include https://releases.llvm.org/2.8/LICENSE.TXT
// #grant none
// ==/UserScript==
const pre = document.querySelector('body > pre');
pre.textContent = pre.textContent.replaceAll('LLVM', "Ernst Blofeld");

Tampermonkey script not auto-updating

At the top of my script I have the following:
// ==UserScript==
// #name Test script
// #description testing auto-update
// #namespace http://tampermonkey.net/
// #author newbie
// #version 1.0.0
// #updateURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// #downloadURL https://github.com/mygithubaccount/test/raw/master/test.user.js
// #match http://awebsite.com/*
// #run-at document-end
// #grant GM_getResourceText
// #grant GM_addStyle
// #grant GM_xmlhttpRequest
// #grant GM_getResourceURL
// #grant GM_xmlhttpRequest
// ==/UserScript==
Please note that these values are just for example.
When I make changes on the script and increase the version number on github and then push the changes to master it updates the raw script link, however I don't get auto-updates from Tampermonkey as in popups saying the script has an update. It will only update if I manually go to the link and reinstall the script to update it.
How can I make this auto-update with popups?
I am not an expert at userscripts, can only tell from my experience making TamperMonkey work:
In order for TamperMonkey to update, I had to copy&paste the URL into Update URL: on the script's Settings tab:
(Make sure ☒ Check for updates is turned on, obviously.)
Then if you manually Check for userscript updates on the TamperMonkey icon, you should see a proper popup.

Resources