// ==UserScript== // @name BTDigg_Chart_Adder // @namespace BTDigg_Chart_Adder // @id BTDigg_Chart_Adder // @description adds BTDigg popularity chart for Bit-torrent magnet-links // @version 0.2.4 // @author KOLANICH // @copyright KOLANICH, 2014 // @homepageURL https://github.com/KOLANICH/BTDigg_Chart_Adder/ // @icon https://btdigg.org/favicon.ico // @license GNU GPL v3 // @screenshot ./images/screenshots/tpb.png ./images/screenshots/btdigg.png ./images/screenshots/nnm-club.ru.png ./images/screenshots/kickasstorrents.com.png ./images/screenshots/extratorrent.com.png // @contributionURL https://github.com/KOLANICH/BTDigg_Chart_Adder/fork // @contributionAmount feel free to fork and contribute // @include * // @exclude /https?\:\/\/btdigg\.org.+/i // @noframes 1 // @run-at document-idle // @optimize 1 // @resource flotr2lib https://raw.github.com/HumbleSoftware/Flotr2/master/flotr2.min.js // @resource tooltipcss ./tooltip.css // @resource preloader ./images/preloader.png // @btdiggBaseURL http://api.btdigg.org/api/public-8e9a50f8335b964f // @tooltipWidth 600 // @tooltipHeight 200 // @installationReportIteration 1 // @scriptId 4706 // ==/UserScript== /* Preloader by http://preloaders.net/ Tooltip by http://cssarrowplease.com/ This script is distributed under conditions of GNU GPL v3. */ /* Copyright (C) 2013-2014 KOLANICH This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ var btdiggApiBaseURL=GM_getMetadata("btdiggbaseurl")[0]; var tooltipWidth=GM_getMetadata("tooltipwidth")[0]; var tooltipHeight=GM_getMetadata("tooltipheight")[0]; var preloader=new Image(); preloader.src=GM_getResourceURL("preloader"); var arrowHeight=40; var parseURIRx=/(\w+)=([^&]+)/ig; var infohashRx=/[A-F0-9]{40}|[A-Z2-7]{32}/i; var site=null; var currentLink=null; var BTDiggReportingEnabled=GM_getValue("enableBTDiggReporting",-1); if(BTDiggReportingEnabled==-1){ alert("Usage of this userscript may be very dangerous. Using this you will allow BTDigg site to gather information about magnet links YOU see. This destroys our privacy. We know nothing about BTDigg true intentions, they may be working for copyrust.\nAnother risk is that BTDigg have ssl certificate only for www.btdigg.com and btdigg.com, but noot for api.btdigg.com, so we have to USE UNENCRYPTED PROTOCOL, WHICH MAKES ANYONE WHO CANE EAVESDROP YOUR INTERNET CONNECTION, INCLUDING GOVERNMENT AGENCIES, KNOW WHAT LINKS DO YOU REQUEST STATISTICS FOR"); alert("Remember:\nYOU DO THIS AT YOUR OWN RISK!!!\n THE AUTHOR(S) IS (ARE) NOT LIABLE FOR ANY DAMAGE OF ANY KIND OR LAW VIOLATION!!!"); alert("Look BTDigg privacy policy..."); GM_openInTab("https://btdigg.org/about/privacypolicy.html"); alert("... and Terms of Service"); GM_openInTab("https://btdigg.org/about/termsofservice.html"); enableBTDiggReporting(); } reportInstallationIfNeeded(); function GM_xhrPr(obj){ return function(resolve, reject) { obj.onload=resolve; obj.onerror=reject; GM_xmlhttpRequest(obj); }; } function reportInstallationIfNeeded(){ const instReptItKey="installationReportIteration"; var instReptIt=GM_getMetadata(instReptItKey.toLowerCase())[0]; if(GM_getValue(instReptItKey,0)findCSRFToken(xhr.responseText)) .then((token)=>{ new Promise(GM_xhrPr({ url:"https://greasyfork.org/script_sets/add_to_set",method:"POST", ignoreCache:true, data:"utf8=%E2%9C%93&authenticity_token="+encodeURIComponent(token)+"&action-set=ai-336&script_id="+scriptId, headers:{"Content-Type":"application/x-www-form-urlencoded"} })) .then((xhr)=>findCSRFToken(xhr.responseText)) .then((token)=>{ new Promise(GM_xhrPr({ url:greaseForkScripts+scriptId+"/install-ping?authenticity_token="+token, method:"POST", ignoreCache:true })) .then((xhr)=>GM_setValue(instReptItKey,instReptIt)); }); }); } } function findCSRFToken(source){ const tokenFieldRx=/]*name=(['"])csrf-token\1[^<>]*\/>/i const valueRx=/content=(["'])([A-Z0-9+=]*)\1/i; let m=source.match(tokenFieldRx); if(m[0]){ m=m[0].match(valueRx); if(m[2])return m[2]; } return false; } function enableBTDiggReporting(){ if( confirm("Would you like to send BTDigg info about all magnet links clicked by you? I don't recommend you to do this, because any collected information may be used against you in a court of (sword) law. Make sure you wouldn't download anything illegal or copyrighted when you enabled this!!! This feature was implemented because I could implement it and I hope it will help BTDigg to index maget links.") && prompt("YOU DO THIS AT YOUR OWN RISK!!!\n THE AUTHOR(S) IS (ARE) NOT LIABLE FOR ANY DAMAGE OF ANY KIND OR LAW VIOLATION!!!\n Now you were warned.\nA you really sure?\nType \"I am warned and accept.\" if you really want to enable this feature.")=="I am warned and accept." ){ GM_setValue("enableBTDiggReporting",1); alert("BTDigg is now \"spying\" on you\nYou can disable it via script menu."); window.location.reload(); return; } else{ alert("Wise decision"); }; GM_setValue("enableBTDiggReporting",0); } if(BTDiggReportingEnabled==1){ GM_registerMenuCommand("BTDigg: disable reporting",function(){ BTDiggReportingEnabled=0; GM_setValue("enableBTDiggReporting",BTDiggReportingEnabled); alert("Espionage stopped!!!"); window.location.reload(); }); } function checkPlottingLibrary(){ if(window.Flotr === undefined){ eval(GM_getResourceText("flotr2lib")); } } var cssInjected=false; function checkCssStyle(){ if(!cssInjected)GM_addStyle(GM_getResourceText("tooltipcss")); } /*! @param btdescriptor { link: объект ссылки, infohash:инфохеш, ещё что-либо } */ function BTDescriptor(uri){ if(uri)this.parseMagnetURI(uri); console.log(this); }; BTDescriptor.prototype.parseMagnetURI=function(uri){ parseURIRx.lastIndex=0; var arr=uri.match(parseURIRx); for(var i=0;i