Skip to content

Instantly share code, notes, and snippets.

@jarble
Created February 23, 2020 03:39
Show Gist options
  • Save jarble/7cf5a6774681e186045a7593ec3bf963 to your computer and use it in GitHub Desktop.
Save jarble/7cf5a6774681e186045a7593ec3bf963 to your computer and use it in GitHub Desktop.
A Greasemonkey script with a "whitelist" of keywords
// ==UserScript==
// @name Search redirector
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author Anderson Green
// @match *://*/*
// @grant none
// ==/UserScript==
//alert(window.location.href);
//var topics = "datalog|earley parser|minizinc|satisfiability modulo|logic programming|differential equations|integration by parts|parser generator|polynomial long division|disjunctive normal form|conjunctive normal form".split("|");
var topics = "linear algebra|dot product|linear independence|basis vector|Gaussian elimination|differential equations|trigonmetric identities|related rates|separable differential equations|polynomial long division|integration by parts|synthetic division|polar coordinates|double angle formula|exact differential equations".split("|");
//var hours = Math.abs(Date.parse('01 Jan 1970 00:00:00 GMT') - (new Date()))*1000.0 / 36e5;
var topic = topics[Math.floor(Math.random() * topics.length)];
//alert(Math.floor(hours % topics.length));
//alert(topic);
var oldURL = document.referrer;
//alert(oldURL);
var to_match = new RegExp(topics.join("|"), "i");
//var to_match = /logic programming|smt-lib/i;
var url = window.location.toString();
var search_term = topic.replace(" ","+");
if(url.indexOf("www\.google\.com\/search") !== -1 && url.indexOf("q\=") !== -1 && !(to_match.test (document.body.innerHTML)) && (url.indexOf("www.google.com/search?q=") !== -1) && !(/ogs\.google\.com|google\.com\/sorry/i.test (window.location.href))){
window.location = url.replace(/q\=/, 'q="'+search_term+'" ');
//alert(to_match);
}
else if (!(to_match.test (document.body.innerHTML) ) && !(/ogs\.google\.com|google\.com\/sorry|www\.google\.com\/search\?q\=/i.test (window.location.href))){
//alert(to_match);
//alert(window.location.href);
window.history.go(-1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment