Skip to content

Commit a015794

Browse files
committed
Add two scripts I've been forgetting to upload for a long time now, reddit_hide_by_subreddit.user.js and simple_url_tracker_cleaner.user.js
Update README.md accordingly, and also mention the K-Meleon browser.
1 parent ab36f46 commit a015794

File tree

3 files changed

+177
-1
lines changed

3 files changed

+177
-1
lines changed

README.md

+30-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ They may also work with GreaseMonkey, TamperMonkey, or on other browsers.
1414
</sub>
1515
-->
1616
### Other
17-
* If you use [Pale Moon](http://www.palemoon.org/) or [Basilisk](https://www.basilisk-browser.org), try [this fork of GreaseMonkey v3][GreaseMonkey_v3_Moonchild].<br>
17+
* If you use [Pale Moon](https://www.palemoon.org), [Basilisk](https://www.basilisk-browser.org), or [K-Meleon](http://kmeleonbrowser.org), try [this fork of GreaseMonkey v3][GreaseMonkey_v3_Moonchild].<br>
1818
Some scripts will likely require modifications for this to work; if you do this yourself, please submit a pull request so that others may also benefit.
1919

2020
## Important note:
@@ -60,6 +60,8 @@ To add a script:
6060
| [Ubuntu Packages Description In Title](#UPDIT) | [install][raw-UPDIT] | N/A | :heavy_check_mark: | MIT | 2023:05:11 | 2023:05:11 |
6161
| [Quietly Reject StackExchange Cookies](#QRSC) | [install][raw-QRSC] | N/A | :heavy_check_mark: | MIT | 2023:05:14 | 2023:05:14 |
6262
| [PyPI Description In Title](#PDIT) | [install][raw-PDIT] | N/A | :heavy_check_mark: | MIT | 2023:05:31 | 2023:05:31 |
63+
| [Simple URL Tracker Cleaner](#SUTC) | [install][raw-SUTC] | N/A | :heavy_check_mark: | MIT | 2021:08:10 | 2023:07:02 |
64+
| [Old Reddit Hide Posts By Sub](#ORHS) | [install][raw-ORHS] | N/A | :heavy_check_mark: | MIT | 2022:04:08 | 2023:07:02 |
6365

6466
<!-- | [GitHub PR Obvious Fork Compare Button](#GPOFCB) | [install][raw-GPOFCB] | N/A | :heavy_check_mark: | MIT | 2021:03:16 | 2021:03:16 | -->
6567
<!-- | [Crates.io Common Meta Near Top](#CCMNT) | [install][raw-CCMNT] | N/A | :heavy_check_mark: | MIT | 2021:03:16 | 2021:04:05 | -->
@@ -378,6 +380,31 @@ Also doesn't use that centered dot character as a separator.
378380

379381
[[Install]][raw-PDIT]
380382

383+
---
384+
385+
<a name="SUTC"></a>
386+
### Simple URL Tracker Cleaner
387+
388+
Scrub various common tracker parameters from URLs. Even if you don't mind being tracked, parameters like these often make URLs rather long; why copy, share, or save a 200 character URL when you could get the exact same content by removing 160 of those characters, without routing traffic through some URL shortening service?
389+
390+
Primarily targets parameters related to Google, Amazon, and Facebook.
391+
392+
<sub>
393+
Icon from: <a href="https://www.flaticon.com/free-icon/fly-swatter_185441" title="Fly Swatter">Fly Swatter free icon created by Freepik - Flaticon</a>
394+
</sub>
395+
[[Install]][raw-SUTC]
396+
397+
---
398+
399+
<a name="ORHS"></a>
400+
### Old Reddit Hide Posts By Sub
401+
402+
Hide posts from arbitrary subreddits (unless specifically looking at them, of course).
403+
404+
Only works for old.reddit.com, not www.reddit.com, because the not only does the latter use a DOM structure that makes it unsuitable for applying styles to entire post-elements by the CSS selector of the child element holding the subreddit, it _also_ commits the desktop (and frankly, even mobile) user-experience war-crime of infinite pagination (endless scrolling). **TLDR: Modern Reddit UI sucks, and supporting it would take more effort than I'm willing to put in to this for my own use.**
405+
406+
[[Install]][raw-ORHS]
407+
381408
---
382409
<!--
383410
@@ -496,6 +523,8 @@ As explained on <https://stackoverflow.com/questions/7653483/github-relative-lin
496523
[raw-UPDIT]: /ubuntu_packages_description_in_title.user.js?raw=1
497524
[raw-QRSC]: /quietly_reject_stackexchange_cookies.user.js?raw=1
498525
[raw-PDIT]: /pypi_description_in_title.user.js?raw=1
526+
[raw-SUTC]: /simple_url_tracker_cleaner.user.js?raw=1
527+
[raw-ORHS]: /reddit_hide_by_subreddit.user.js?raw=1
499528

500529
<!-- Legacy Workaround Scripts -->
501530
[raw-GLHW]: /legacy_browser_workarounds/github_line_hyperlink_workaround.user.js?raw=1

reddit_hide_by_subreddit.user.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// ==UserScript==
2+
// @name Hide Posts By Subreddit
3+
// @namespace https://github.com/StaticPH
4+
// @match https://old.reddit.com/*
5+
// @version 1.1
6+
// @createdAt 4/8/2022, 6:34:35 PM
7+
// @author StaticPH
8+
// @description Hide posts from arbitrary subreddits. ONLY FOR old.reddit.com!
9+
// @license MIT
10+
// @updateURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/reddit_hide_by_subreddit.user.js
11+
// @downloadURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/reddit_hide_by_subreddit.user.js
12+
// @homepageURL https://github.com/StaticPH/UserScripts
13+
// @supportURL https://github.com/StaticPH/UserScripts/issues
14+
// @icon https://www.redditstatic.com/desktop2x/img/favicon/favicon-32x32.png
15+
// @grant GM.setValue
16+
// @grant GM_setValue
17+
// @grant GM.getValue
18+
// @grant GM_getValue
19+
// @grant GM.addStyle
20+
// @grant GM_addStyle
21+
// @noframes
22+
// @run-at document-start
23+
// ==/UserScript==
24+
25+
(function(){
26+
"use strict";
27+
28+
const settings = {
29+
/* An array of names (strings) of subreddits from which posts should be hidden. */
30+
hideSubredditsNamed: [],
31+
};
32+
33+
// Prefer asychronous Greasemonkey4-API GM.* methods, but allow use of GM_* methods as a fallback if necessary.
34+
if (typeof GM === 'undefined'){
35+
this.GM = {};
36+
}
37+
Object.entries({
38+
'GM_getValue': 'getValue',
39+
'GM_setValue': 'setValue',
40+
'GM_addStyle': 'addStyle'
41+
}).forEach((gm3Name, gm4Name) => {
42+
if (GM[gm4Name] === 'undefined'){
43+
const fallback = this[gm3Name];
44+
if (!fallback){
45+
throw new ReferenceError('Unable to find ' + gm3Name + ' to use as fallback for the unavailable GM.' + gm4Name + ' method!');
46+
}
47+
console.log('GM.' + gm4Name + ' is not defined. Falling back to ' + gm3Name + ' Promise.');
48+
GM[gm4Name] = function(...args){
49+
return new Promise((onResolve, onReject) => {
50+
try{ onResolve(fallback.apply(this, args)); }
51+
catch(err){ onReject(err); }
52+
});
53+
}
54+
}
55+
});
56+
57+
function readSettings(){
58+
for(let key in settings){
59+
settings[key] = GM.getValue(key, settings[key]);
60+
}
61+
}
62+
63+
function saveSettings(){
64+
for(let key in settings){
65+
GM.setValue(key, settings[key]);
66+
}
67+
}
68+
69+
readSettings();
70+
saveSettings();
71+
72+
if (settings.hideSubredditsNamed.length < 1){
73+
console.log('No subreddits to hide.');
74+
return;
75+
}
76+
77+
const selectorStrBuilder = (subredditName) => 'div.thing[data-subreddit="' + subredditName + '"]';
78+
79+
GM.addStyle(Array.from(settings.hideSubredditsNamed, selectorStrBuilder).join(', ') + '{ display: none; }');
80+
81+
})();

simple_url_tracker_cleaner.user.js

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// ==UserScript==
2+
// @name Simple URL Tracker Cleaner
3+
// @namespace https://github.com/StaticPH
4+
// @match *://*/*
5+
// @version 1.3
6+
// @createdAt 8/10/2021
7+
// @author StaticPH
8+
// @description Scrub various common tracker parameters from URLs.
9+
// @license MIT
10+
// @updateURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/simple_url_tracker_cleaner.user.js
11+
// @downloadURL https://raw.githubusercontent.com/StaticPH/Userscripts/master/simple_url_tracker_cleaner.user.js
12+
// @homepageURL https://github.com/StaticPH/UserScripts
13+
// @supportURL https://github.com/StaticPH/UserScripts/issues
14+
// @icon https://cdn-icons-png.flaticon.com/32/185/185441.png
15+
// @grant none
16+
// @run-at document-end
17+
// ==/UserScript==
18+
// Icon from https://www.flaticon.com/free-icon/fly-swatter_185441; All rights belong to their original owner(s).
19+
20+
(function(){
21+
'use strict';
22+
23+
async function cleanURLs(){
24+
Array.from(document.links).forEach(async function(link){
25+
let fixed = null;
26+
if (link.href.match(/google\.[^/]+\/url\?.*/)){
27+
const url = new URL(link.href);
28+
if (url.searchParams.has('url')){
29+
fixed = url.searchParams.get('url');
30+
if (!fixed || fixed.length === 0){ console.warn('Found empty "url" parameter in link: ' + link.href); }
31+
else{
32+
console.log( link.href + ' --> ' + fixed );
33+
link.href = fixed;
34+
}
35+
}
36+
else {
37+
console.warn('Could not find expected "url" parameter for link: ' + link.href);
38+
}
39+
}
40+
if (link.href.match(/(?:[?&])(utm_(source|medium|campaign|term|content)|(fb|g)clid)=[^&?#]*[&?#]?/)){
41+
fixed = link.href.replace(/(?:[?&])(utm_(source|medium|campaign|term|content)|(fb|g)clid)=[^&?#]*/g, '').replace(/[?&]*#/, '#').replace(/[?&]*$/, '');
42+
console.log( link.href + ' --> ' + fixed );
43+
link.href = fixed;
44+
}
45+
// if (link.href.match(/google\.[^/]+\/search\?q=.+/)){
46+
if (link.href.match(/google\.[^/]+\/search\?q=.*?\&(ei|sa|ved|bi[wh]|spell|oq|gs_lcp|sclient|uact)=[^&?#]*/)){
47+
fixed = link.href.replace(/\&(ei|sa|ved|bi[wh]|spell|oq|gs_lcp|sclient|uact)=[^&?#]*/g, '');
48+
console.log( link.href + ' --> ' + fixed );
49+
link.href = fixed;
50+
}
51+
// TODO: AMAZON URLS
52+
// On Amazon product pages in particular, you can remove keywords, ref, dchild, pd*, pf*, qid, and sr
53+
if (link.href.match(/amazon\.[^/]+\/[^/]+\/dp\/[^/]+\/[^?&]+[?&]/)){
54+
fixed = link.href.replace(/[&?].+$/, '');
55+
console.log( link.href + ' --> ' + fixed );
56+
link.href = fixed;
57+
}
58+
});
59+
return;
60+
}
61+
62+
cleanURLs();
63+
setInterval(cleanURLs, 5000);
64+
// Apparently calling `cleanURLs()` in the setInterval call violates CSP on google pages, because something decides to try interpreting a simple string as javascript.
65+
66+
})();

0 commit comments

Comments
 (0)