github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/net/http/proxy1/tamper-monkey-rightclick-menu.js (about) 1 // ==UserScript== 2 // @name rightclick-menu 3 // @description include jQuery and make sure window.$ is the content page's jQuery version, and this.$ is our jQuery version. http://stackoverflow.com/questions/28264871/require-jquery-to-a-safe-variable-in-tampermonkey-script-and-console 4 // @namespace http://your.homepage/ 5 // @version 0.131 6 // @author iche 7 // @downloadURL http://localhost:8085/mnt01/tamper-monkey-rightclick-menu.js 8 // @updateURL http://localhost:8085/mnt01/tamper-monkey-rightclick-menu.js //serving the head with possibly new version 9 // // https://developer.chrome.com/extensions/match_patterns 10 // @match *://*.welt.de/* 11 // @match *://*.handelsblatt.com/* 12 // @match *://*.focus.de/* 13 // @exclude *://*/*.png 14 // @exclude *://*/*.jpg 15 // // @include /^https?:\/\/www.flickr.com\/.*/ 16 17 // // @require http://cdn.jsdelivr.net/jquery/2.1.3/jquery.min.js 18 // @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js 19 // @grant none 20 // @noframes 21 // @run-at document-end 22 // ==/UserScript== 23 24 25 // fallback http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/ 26 if (typeof jQuery === 'undefined') { 27 console.log("CDN blocked by Iran or China?"); 28 document.write(unescape('%3Cscript%20src%3D%22/path/to/your/scripts/jquery-2.1.4.min.js%22%3E%3C/script%3E')); 29 } 30 31 (function ($, undefined) { 32 $(function () { 33 //isolated jQuery start; 34 console.log("about to add right click handler; " + $.fn.jquery + " Version"); 35 36 37 var menuHtml = "<div id='menu01' style='background-color:#ccc;padding:4px;z-index:1000;display:none'>"; 38 //menuHtml += " <li>item1</li>" ; 39 menuHtml += " <li id='menu01-item02' style='height:64px;'>item2</li>" ; 40 menuHtml += "</div>" ; 41 42 $("body").append(menuHtml); 43 44 $('#menu01').on('click', function(e) { 45 $('#menu01').hide(); 46 }); 47 48 $(document).on('click', function(e) { 49 $('#menu01').hide(); 50 }); 51 52 53 function logX(arg01){ 54 console.log( "menu called " + arg01); 55 } 56 57 function showContextMenu(kind, evt){ 58 59 logX( kind + " 1 - x" + evt.pageX + " - y" + evt.pageY ); 60 var obj = $(evt.target); 61 var parAnchor = obj.closest("a"); // includes self 62 63 64 if (parAnchor.length>0) { 65 var domainX = document.domain; 66 var href = obj.attr('href'); 67 if (href.indexOf('/') == 0) { 68 href = domainX + href 69 } 70 var text = obj.text() 71 if (text.length > 100){ 72 var textSh = ""; 73 textSh = text.substr(0,50); // start, end 74 textSh += " ... "; 75 textSh += text.substr(text.length-50,text.length-1); 76 text = textSh; 77 } 78 79 var formHtml = ""; 80 var prox01 = "http://localhost:8085/dedup"; 81 var prox02 = "https://libertarian-islands.appspot.com/dedup"; 82 83 formHtml += "<form action='"+prox01+"' method='post' "; 84 formHtml += " target='proxy-window' >"; 85 formHtml += "<input type='hidden' name='url-x' value='"+href+"' >"; 86 formHtml += "<input type='submit' value='subm' >"; 87 formHtml += "</form>"; 88 89 var innerH = ""; 90 innerH += "<a target='proxy-window' href='"+prox01 + "?url-x="+ href+"' >" + text + "</a>"; 91 innerH += formHtml; 92 $('#menu01-item02').html(innerH); 93 } 94 95 var fromBottom = evt.pageY - $('#menu01').height() - 8; 96 $('#menu01').css({ 97 "position": "absolute", 98 "top": fromBottom + "px", 99 "left": evt.pageX + "px", 100 }); 101 $('#menu01').show(); 102 103 104 logX( kind + " 2"); 105 } 106 107 108 109 110 $(document).on('contextmenu', function(e){ 111 e.stopPropagation(); // before 112 //e.preventDefault(); // prevent browser context menu from appear 113 showContextMenu("allbrows",e); 114 }); 115 116 117 console.log("right click handler added"); 118 119 120 121 //isolated jQuery end; 122 }); 123 })(window.jQuery.noConflict(true));