Last active
August 29, 2015 14:06
-
-
Save clojens/5a7eecbf5b7dd599be2e to your computer and use it in GitHub Desktop.
This file contains hidden or 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 URL Observer Addon | |
// @namespace anon | |
// @match http://*/* | |
// @match https://*/* | |
// @exclude http://localhost/* | |
// @version 2 | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js | |
// @grant GM_info | |
// @grant metadata | |
// @grant GM_xmlhttpRequest | |
// @run-at document-end | |
// ==/UserScript== | |
window.addEventListener("load", Greasemonkey_main, false); | |
function Greasemonkey_main () { | |
function GM_main ($) { | |
//alert ('jQuery is installed with no conflicts! The version is: ' + $.fn.jquery); | |
} | |
if (typeof jQuery === "function") { | |
console.log ("Running with local copy of jQuery!"); | |
GM_main (jQuery); | |
} | |
else { | |
console.log ("fetching jQuery from some 3rd-party server."); | |
add_jQuery (GM_main, "1.7.2"); | |
} | |
function add_jQuery (callbackFn, jqVersion) { | |
var jqVersion = jqVersion || "1.7.2"; | |
var D = document; | |
var targ = D.getElementsByTagName ('head')[0] || D.body || D.documentElement; | |
var scriptNode = D.createElement ('script'); | |
scriptNode.src = 'http://ajax.googleapis.com/ajax/libs/jquery/' | |
+ jqVersion | |
+ '/jquery.min.js' | |
; | |
scriptNode.addEventListener ("load", function () { | |
var scriptNode = D.createElement ("script"); | |
scriptNode.textContent = | |
'var gm_jQuery = jQuery.noConflict (true);\n' | |
+ '(' + callbackFn.toString () + ')(gm_jQuery);' | |
; | |
targ.appendChild (scriptNode); | |
}, false); | |
targ.appendChild (scriptNode); | |
} | |
var links = document.links; | |
var aLen = links.length; | |
var href = []; | |
for (var i = 0; i < aLen; i++) | |
{ | |
href.push(links[i].href); | |
//console.log(href); | |
} | |
var hrefs = JSON.stringify(href); | |
console.log(hrefs); | |
GM_xmlhttpRequest({ | |
method: "POST", | |
url: "http://localhost/webhooks/urls.php", | |
data: hrefs, | |
headers: { 'Content-Type': 'application/json; charset=UTF-8' }, | |
onload: function(response) { | |
console.log('gm:' + r.responseText); | |
} | |
}); | |
} |
This file contains hidden or 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
<?php | |
# I trust I need not explain this? | |
mysql_connect('localhost', '', ''); | |
mysql_select_db('my_index'); | |
$data = file_get_contents("php://input"); | |
$urls = json_decode($data); | |
foreach($urls as $url) | |
{ | |
$host = parse_url($url, PHP_URL_HOST); | |
$domain = mysql_real_escape_string($host); | |
$hash = md5($url); | |
$url = mysql_real_escape_string($url); | |
mysql_query("INSERT IGNORE INTO urls (url,hash,host) VALUES ('$url','$hash','$domain') ON DUPLICATE KEY UPDATE url='$url'"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment