Created
January 15, 2018 13:17
-
-
Save buzamahmooza/2a7e27d0e24677568b50c8776df20db3 to your computer and use it in GitHub Desktop.
A library for my commonly used JavaScript functions with user scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Faris Handy Webdev JavaScript functions | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description A bunch of useful JavaScript functions | |
// @description This is not a regular script for you to run! Only use this via the @require keyword. | |
// @author Faris Hijazi | |
// @grant unsafeWindow | |
// ==/UserScript== | |
const DEBUG = false; | |
const GoogleImagesSearchURL = "https://www.google.com/search?&hl=en&tbm=isch&q="; | |
unsafeWindow.log = log; | |
unsafeWindow.matchSite = matchSite; | |
unsafeWindow.GoogleImagesSearchURL = GoogleImagesSearchURL; | |
unsafeWindow.ddgProxy = ddgProxy; | |
unsafeWindow.createElement = createElement; | |
// You can use this to create an element by typing it's HTML. | |
// example: var myAnchor = createElement('<a href="google.com">Go to google</a>'); | |
function createElement(html) { | |
var div = document.createElement('div'); | |
div.innerHTML = html; | |
return div.childNodes[0]; | |
} | |
function matchSite(siteRegex){ | |
let result = location.href.match(siteRegex); | |
if(result) console.log("Site matched regex: "+siteRegex); | |
return result; | |
} | |
// DuckDuckGo proxy url | |
function ddgProxy(url){ let prxy=("https://proxy.duckduckgo.com/iu/?u=" + decodeURI(url) + "&f=1"); return prxy; } | |
function log(msg){ | |
if(DEBUG){ console.log('log: ' + msg); } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment