Skip to content

Commit

Permalink
Generate tamper-monkey-script
Browse files Browse the repository at this point in the history
  • Loading branch information
davegallant committed Jan 14, 2024
1 parent 40d8be8 commit 491bae2
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 106 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/tamper-monkey.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "Generate Tampermonkey script"
on:
pull_request:

jobs:
gomplate:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install gomplate
run: |
wget -O gomplate https://github.com/hairyhenderson/gomplate/releases/download/v3.10.0/gomplate_linux-amd64
chmod +x gomplate
sudo mv gomplate /usr/local/bin/
- name: Run gomplate
run: gomplate < script.js.tmpl > script.js

- name: Check for changes
id: check_changes
run: |
git diff --exit-code || echo "Changes found"
- name: Commit and push changes
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add .
git commit -m "Update script.js using gomplate" || true
git push
Binary file added icon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
211 changes: 105 additions & 106 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,114 +10,113 @@
// @version 0.0.1
// ==/UserScript==

(function() {
'use strict';
(function () {
"use strict";

var Links = document.querySelectorAll('a.postlink, a.autolinker_link');
var Links = document.querySelectorAll("a.postlink, a.autolinker_link");

const REDIRECT_REGEX = [
{
name: 'Amazon',
pattern: 'www.amazon.ca/gp/redirect.html\\?ie=UTF8&location=(?<baseUrl>.*?)(&|ref%3D|%3F)',
},
{
name: 'Best Buy',
pattern: 'bestbuyca.(.*).net(.*)\\?u=(?<baseUrl>.*)',
},
{
name: 'HP',
pattern: 'www.awin1.com(.*)\&clickref=\&p=(?<baseUrl>.*)\&.*',
},
{
name: 'Samsung',
pattern: 'www.awin1.com(.*)\?p=(?<baseUrl>.*)',
},
{
name: 'redirectingat.com',
pattern: 'go.redirectingat.com/.*url=(?<baseUrl>.*).*',
},
{
name: 'homedepot',
pattern: 'the-home-depot-ca.pxf.io(.*)\?u=(?<baseUrl>.*)',
},
{
name: 'redirectingat',
pattern: 'go.redirectingat.com(.*)\?url=(?<baseUrl>.*)',
},
{
name: 'adidas-canada',
pattern: 'adidas-canada.sjv.io(.*)\?u=(?<baseUrl>.*)',
},
{
name: 'canadiantire',
pattern: 'imp.i([0-9]*).net(.*)\?u=(?<baseUrl>.*)',
},
{
name: 'kqzyfj',
pattern: 'www.awin1.com(.*)\?ued=(?<baseUrl>.*)',
},
{
name: 'lenovo',
pattern: '(.*).evyy.net(.*)\?u=(?<baseUrl>.*)',
},
{
name: 'thesource',
pattern: 'www.kqzyfj.com(.*)?url=(?<baseUrl>.*)&sid=.*',
},
{
name: 'walmart',
pattern: 'click.linksynergy.com(.*)\?murl=(?<baseUrl>.*)&u1=.*',
},
{
name: 'dpbolvw.net',
pattern: 'www.dpbolvw.net(.*)?url=(?<baseUrl>.*)',
},
{
name: "jdoqocy.com",
pattern: "www.jdoqocy.com(.*)?url=(?<baseUrl>.*)&sid=.*"
},
{
name: 'pxf.io',
pattern: '(.*).pxf.io(.*)\?u=(?<baseUrl>.*)',
},
{
name: 'avantlink.com',
pattern: '(.*).avantlink.com(.*)\?url=(?<baseUrl>.*)',
},
{
name: "anrdoezrs.net",
pattern: ".*anrdoezrs\\.net.+\\?url=(?<baseUrl>.*)&sid=.+"
},
{
name: "tkqlhce.com",
pattern: ".*tkqlhce\\.com.+?url=(?<baseUrl>.*)&sid=.*"
},
{
name: "staples",
pattern: ".*staplescanada\\.4u8mqw\\.net.+\\?u=(?<baseUrl>.*)"
const REDIRECT_REGEX = [
{
name: "Amazon",
pattern:
"www.amazon.ca/gp/redirect.html\\?ie=UTF8&location=(?<baseUrl>.*?)(&|ref%3D|%3F)",
},
{
name: "Bst Buy",
pattern: "bestbuyca.(.*).net(.*)\\?u=(?<baseUrl>.*)",
},
{
name: "HP",
pattern: "www.awin1.com(.*)&clickref=&p=(?<baseUrl>.*)&.*",
},
{
name: "Samsung",
pattern: "www.awin1.com(.*)?p=(?<baseUrl>.*)",
},
{
name: "redirectingat.com",
pattern: "go.redirectingat.com/.*url=(?<baseUrl>.*).*",
},
{
name: "homedepot",
pattern: "the-home-depot-ca.pxf.io(.*)?u=(?<baseUrl>.*)",
},
{
name: "redirectingat",
pattern: "go.redirectingat.com(.*)?url=(?<baseUrl>.*)",
},
{
name: "adidas-canada",
pattern: "adidas-canada.sjv.io(.*)?u=(?<baseUrl>.*)",
},
{
name: "canadiantire",
pattern: "imp.i([0-9]*).net(.*)?u=(?<baseUrl>.*)",
},
{
name: "underarmour",
pattern: "www.awin1.com(.*)?ued=(?<baseUrl>.*)",
},
{
name: "lenovo",
pattern: "(.*).evyy.net(.*)?u=(?<baseUrl>.*)",
},
{
name: "kqzyfj",
pattern: "www.kqzyfj.com(.*)?url=(?<baseUrl>.*)&sid=.*",
},
{
name: "walmart",
pattern: "click.linksynergy.com(.*)?murl=(?<baseUrl>.*)&u1=.*",
},
{
name: "dpbolvw.net",
pattern: "www.dpbolvw.net(.*)?url=(?<baseUrl>.*)",
},
{
name: "jdoqocy.com",
pattern: "www.jdoqocy.com(.*)?url=(?<baseUrl>.*)&sid=rfdcb",
},
{
name: "pfx.io",
pattern: "(.*).pxf.io(.*)?u=(?<baseUrl>.*)",
},
{
name: "avantlink.com",
pattern: "(.*).avantlink.com(.*)?url=(?<baseUrl>.*)",
},
{
name: "anrdoezrs.net",
pattern: ".*anrdoezrs\\.net.+\\?url=(?<baseUrl>.*)&sid=.*",
},
{
name: "tkqlhce.com",
pattern: ".*tkqlhce\\.com.+?url=(?<baseUrl>.*)&sid=.*",
},
{
name: "staples",
pattern: ".*staplescanada\\.4u8mqw\\.net.+\\?u=(?<baseUrl>.*)",
},
];
var StripRedirect = function (URL) {
for (var i = 0; i < REDIRECT_REGEX.length; i++) {
var rule = REDIRECT_REGEX[i];
var result = new RegExp(rule.pattern).exec(URL);
if (result) {
var newURL = result.groups.baseUrl;
try {
return decodeURIComponent(newURL);
} catch (e) {
console.log(e);
return URL;
}
}
];

var StripRedirect = function(URL) {
for (var i = 0; i < REDIRECT_REGEX.length; i++) {
var rule = REDIRECT_REGEX[i];
var result = new RegExp(rule.pattern).exec(URL);
if (result) {
var newURL = result.groups.baseUrl;
try {
return decodeURIComponent(newURL);
} catch (e) {
console.log(e);
return URL;
}
}
}
return URL;
};

Links.forEach(function(Link) {
var ReferralURL = Link.href;
Link.href = StripRedirect(ReferralURL);
});
}
return URL;
};

Links.forEach(function (Link) {
var ReferralURL = Link.href;
Link.href = StripRedirect(ReferralURL);
});
})();
42 changes: 42 additions & 0 deletions script.js.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// ==UserScript==
// @name RedFlagDeals Redirect Stripper
// @author Dave Gallant
// @description Strip redirect links on forums.redflagdeals.com
// @downloadURL https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/script.js
// @grant none
// @match *://forums.redflagdeals.com/*
// @namespace http://tampermonkey.net/
// @updateURL https://raw.githubusercontent.com/davegallant/rfd-redirect-stripper/main/script.js
// @version 0.0.1
// ==/UserScript==

(function() {
'use strict';

var Links = document.querySelectorAll('a.postlink, a.autolinker_link');

const REDIRECT_REGEX = {{ file.Read "redirects.json" }};

var StripRedirect = function(URL) {
for (var i = 0; i < REDIRECT_REGEX.length; i++) {
var rule = REDIRECT_REGEX[i];
var result = new RegExp(rule.pattern).exec(URL);
if (result) {
var newURL = result.groups.baseUrl;
try {
return decodeURIComponent(newURL);
} catch (e) {
console.log(e);
return URL;
}
}
}
return URL;
};

Links.forEach(function(Link) {
var ReferralURL = Link.href;
Link.href = StripRedirect(ReferralURL);
});

})();

0 comments on commit 491bae2

Please sign in to comment.