ADictionary Blocker

A Ad-changer

  1. // ==UserScript==
  2. // @name ADictionary Blocker
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description A Ad-changer
  6. // @author Thomas Thy Train
  7. // @match *://dictionary.cambridge.org/*
  8. // @match https://*/*
  9. // @grant GM_addStyle
  10. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js
  12. // @grant GM.setValue
  13. // @grant GM.getValue
  14. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAIAAABMXPacAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAmLSURBVHhe7Z3Pa+NIFse1gwxTErjdNnLCYAYFmrSzA00n9CWQS8Nccvdh8xcMOc3fsofBf0Lm0PdcGnwJ9KWJww676TENLYIP3QlKawWWBhToea9U1i8rceIkqpJcH944spxJZupbeq/q1avKP759+6ZI+PEd+yrhhBSAM1IAzkgBOCMF4IwUgDNSAM5IATgjBeCMFIAzUgDOLJgL+l+zw66qyD8vx+zq8VnkCah26wNF/g/eWYDKt37B3NkFSQEiHsRTySDMGfGeAEOHlwD+aen4qmj+GsE7DXLV0BRr1Dk8x9uPzO9f/2JX1/Cvp9/D6/0fAjEEMNrus5Zntq4a7IbqeEpDu2LvYsjgqPWBXT8qT49+YVcz9H/6N7w+lABcXZDRtvd2wMa9ddckteFwpX/UobZ6cLzaH9Yd9o1TbFJI6wPkyYvodfbtA8JNgGB7C9rdbyhg6smwc3Dc+jCpsQ8B3dvddKcPBMOyNXZVHfgI4O1ufXmJjUkGQ7DVd5PwfgS0/qXJriNUJ/ttFYCDAND6lybtytYIej0Yvc3wdnfAoPVVa4zBN8bTPkoBJA9NsQJ0N8BY91fs5syAEgID9H10PtZo9T0djMb46gW7qhJFCtC2X7fAwjfqyVkmokLrY2CwRmArh+fBs2Zq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2vX8cnsiVS1T4Bdx5t+UjU04BDD2savm8SaLjuPKnZviIhIVfLPUmyAQ4ohJBuMyUSgCjbYfnx/U2w/ktbsaDPo7lQ+k/OAN3uiaYvbdDfRQe3yVC6m2W8lRF3OnE6QjHI8M/6zN/s2MusioiAU0z3LL1VcdTLejvo5X+EZ4slPcXU4SiEnVBj4B8ApYFKQBnpACckQJwRgrAGSkAZ6QAnJECcEYKwBkpAGekAJyRAnBGCpBPmIMrACkAZxZMRz89+gVeyZMX9F51yHR8QdPRv3/9i11J7s0iTwAIsP/fX9n7SlPAE7CgAOF1KAP8Z4Vvq0TY7hFCC7A8CCEAcIMG1XsaMo8CINeEK8WCT0B4kRwOLY874u+CgFwNlgoQ4P6tDywoQESkxBIihACSeyKDMGekAJyRAnBGCsAZKQBnpACckQJwRVH+BhPMStxmCvgjAAAAAElFTkSuQmCC
  15. // @CrossOrigin("*")
  16. // ==/UserScript==
  17.  
  18. // this is from https://dictionary.cambridge.org/external/scripts/dblclick.js?version=5.0.175
  19. function setupExtDoubleClick(websiteUrl, dictionary, showFirstEntry, areaClass, maxAllowedWords, target) {
  20. setupDoubleClick(websiteUrl, dictionary, areaClass, maxAllowedWords, target,
  21. function(websiteUrl, dictionary, showFirstEntry, lookup) { return websiteUrl + "search/" + (dictionary ? dictionary + "/" : "") + (showFirstEntry ? "direct/" : "") + "?q=" + lookup; });
  22. }
  23. function setupDoubleClick(websiteUrl, dictionary, showFirstEntry, areaClass, maxAllowedWords, target, urlCallback) {
  24. //warning message for developers
  25. if (!websiteUrl || !dictionary) {
  26. alert("Please specify required parameters (websiteUrl and dictionary) to setupDoubleClick()")
  27. return;
  28. }
  29.  
  30. //shows the definition layer
  31. var showLayer = function(e) {
  32. var translateDictionary = dictionary;
  33. var node = e.target || e.srcElement;
  34. while (node != null) {
  35. var lang = node.getAttribute("dict");
  36. if (lang) {
  37. translateDictionary = lang;
  38. break;
  39. }
  40. if (node.parentNode == node.ownerDocument) {
  41. break;
  42. }
  43. node = node.parentNode;
  44. }
  45. e.preventDefault();
  46. var lookup = getSelectedText();
  47. // original space, but shitty api ont allow
  48. lookup = lookup.replace(/[\.\*\?;!()\+,\[:\]<>^_`\[\]{}~\\\/\"\'=]/g, "");
  49. lookup = lookup.replace(/\s+/g, "");
  50. if (lookup != null && lookup.replace("/\s/g", "").length > 0) {
  51. //disable the double-click feature if the lookup string
  52. //exceeds the maximum number of allowable words
  53. if (maxAllowedWords && lookup.split(/[ -]/).length > maxAllowedWords)
  54. return;
  55. // i give up on showing the meaning
  56. //I DID IT!!!!!!!
  57. let request = new XMLHttpRequest();
  58. request.open("GET","https://api.dictionaryapi.dev/api/v2/entries/en/"+lookup);
  59. request.responseType="json";
  60. // add a popup to show define
  61. // word is correct
  62. // new,store things
  63. let word="<h3 style='font-style:italic;font-weight:bold;'>power by Cambridge Dictionary</h3><h1 id='word_adb_explain'style='font-style:italic;font-weight:bold;'>"+lookup+"</h1>";
  64. // test zone
  65. if(!localStorage.getItem('wordlist')){
  66. localStorage.setItem("wordlist","");
  67. }
  68. let cur_wl=localStorage.getItem('wordlist').split(":");
  69. //unique
  70. cur_wl=Array.from(new Set(cur_wl));
  71. localStorage.setItem("wordlist",cur_wl.join(":"));
  72. let color="grey";
  73. if(cur_wl.includes(lookup)){
  74. color="green"
  75. }
  76. request.onload=()=>{
  77. //localStorage.clear();
  78.  
  79. request.response[0].meanings.forEach((e)=>{word+="<p>"+e.definitions[0].definition+"</p>";word+="<span style='font-style:italic;opacity:0.5;'>"+e.partOfSpeech+"</span>"});
  80. $("#adb_explain").remove();
  81. $("body").append("<div id='adb_explain'style='position:fixed;background-color:#fff;border:2px solid #000;width:450px;'><button id='delete_block' style='border-radius: 50%;border-width:0px;'>X</button><button id='adb_addword' style='border-radius: 50%;background-color:"+color+";border-width:0px;'>&#10004;</button>"+word+"</div>");
  82.  
  83. // test end
  84. let block=document.querySelector("#adb_explain");
  85. const size=block.getBoundingClientRect();
  86. block.style.left=(1420-size.width).toString()+"px";
  87. block.style.top=(740-size.height).toString()+"px";
  88. $("#delete_block").click(()=>{$("#adb_explain").remove()});
  89. }
  90. $("#adb_addword").click((e)=>{
  91. lookup=$("#word_adb_explain").text();
  92. if(cur_wl.includes(lookup)){
  93. $("#adb_addword").css("background-color","grey");
  94. const index=cur_wl.findIndex((e)=>e===lookup);
  95. delete cur_wl[index];
  96. localStorage.setItem('wordlist', cur_wl.join(":"));
  97. }else{
  98. $("#adb_addword").css("background-color","green");
  99. localStorage.setItem('wordlist', cur_wl.join(":")+":"+lookup);
  100. }
  101. });
  102. request.send();
  103.  
  104. //append the layer to the DOM only once
  105. // modify this part
  106. if ($("#definition_layer").length == 0) {
  107. var imageUrl = websiteUrl + "external/images/doubleclick/definition-layer.gif";
  108. $("body").append("<div id='definition_layer' style='position:absolute; cursor:pointer;'><img src='" + imageUrl + "' alt='' title=''/></div>");
  109. //$("body").append("<div id='definition_layer' style='position:absolute; cursor:pointer;'>" + word + "</div>");
  110. }
  111.  
  112. //move the layer at the cursor position
  113. $("#definition_layer").map(function() {
  114. $(this).css({'left' : e.pageX-30, 'top' : e.pageY-40});
  115. });
  116.  
  117. //open the definition popup clicking on the layer
  118. $("#definition_layer").mouseup(function(e) {
  119. e.stopPropagation();
  120. openPopup(lookup, translateDictionary);
  121. });
  122. } else {
  123. $("#definition_layer").remove();
  124. }
  125. };
  126.  
  127. //opens the definition popup
  128. var openPopup = function(lookup, translateDictionary) {
  129. var searchUrl;
  130. if (urlCallback)
  131. searchUrl = urlCallback(websiteUrl, translateDictionary, showFirstEntry, lookup);
  132. else
  133. searchUrl = websiteUrl + "search/" + (translateDictionary ? translateDictionary + "/" : "") + (showFirstEntry ? "direct/" : "") + "?q=" + lookup;
  134. if(lookup.replace(/[a-zA-Z0-9]/g, '')!=""){
  135. searchUrl="https://www.collinsdictionary.com/dictionary/chinese-english/"+lookup;
  136. }
  137. if (target) {
  138. if (target == "self") {
  139. window.location.href = searchUrl;
  140. return;
  141. }
  142. var popup = window.open(searchUrl, target, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=no,width=915,height=760,top=300,left=300");
  143. if (popup)
  144. popup.focus();
  145. } else {
  146. window.open(searchUrl, 'cup_lookup');
  147. }
  148. /*window.location.href = searchUrl;*/
  149. };
  150.  
  151. var area = areaClass ? "." + areaClass : "body";
  152. $(area).mouseup(showLayer);
  153. }
  154.  
  155. /*
  156. * Cross-browser function to get selected text
  157. */
  158. function getSelectedText(){
  159. if(window.getSelection)
  160. return window.getSelection().toString();
  161. else if(document.getSelection)
  162. return document.getSelection();
  163. else if(document.selection)
  164. return document.selection.createRange().text;
  165. return "";
  166. }
  167. (function() {
  168. 'use strict';
  169. //setup clicker dictionary
  170. // problem, it only give you the link
  171. setupDoubleClick( 'https://dictionary.cambridge.org/', 'english-chinese-traditional', true, null, 5, 'popup' );
  172. let adtype=["iframe","ytd-display-ad-renderer","ins","div"];
  173. let adfinder=["google_ads","aswift","mys-wrapper","midcontentadcontainer"];
  174.  
  175. // let interval = null;
  176.  
  177. // let hostname = document.location.hostname;
  178. //make this the explain page,but not every go ad
  179. // new
  180. function cleanup() {
  181.  
  182. //if(!localStorage.getItem('wordlist')){
  183. // localStorage.setItem("wordlist",".");
  184. //}
  185. let request = new XMLHttpRequest();
  186. let word="Loading"
  187. try{
  188. let cur_wl=localStorage.getItem('wordlist').split(":").slice(1);
  189. let lookup= new String(_.sample(cur_wl));
  190. //let lookup="cat";
  191. request.open("GET","https://api.dictionaryapi.dev/api/v2/entries/en/"+lookup);
  192. request.responseType="json";
  193. word="<h6 style='font-style:italic;font-weight:bold;'>power by Dictionary API</h6><h5 style='font-style:italic;font-weight:bold;'>"+lookup+"</h5>";
  194. }catch(err){
  195. let lookup="Loading";
  196. request.open("GET","https://api.dictionaryapi.dev/api/v2/entries/en/"+lookup);
  197. request.responseType="json";
  198. word="Loading";
  199. }
  200. request.onload=()=>{
  201. request.response[0].meanings.forEach((e)=>{
  202. word+="<p>"+e.definitions[0].definition+"</p>";
  203. word+="<span style='font-style:italic;opacity:0.5;'>"+e.partOfSpeech+"</span>";
  204. });
  205. // clear ad
  206. adtype.forEach((i)=>{
  207. try{
  208. document.querySelectorAll(i).forEach((elem)=>{
  209. adfinder.forEach((adid)=>{
  210. if(elem.id.slice(0,adid.length)==adid){
  211. console.log(word);
  212. elem.style.overflow="auto";
  213. elem.innerHTML=word;
  214. //elem.style.visibility = 'hidden';
  215. //elem.style.width = '1px';
  216. //elem.style.height = '1px';
  217. //elem.style.overflow = 'hidden';
  218. //elem.style.opacity = 0;
  219. //elem.remove();
  220. }
  221. });
  222.  
  223.  
  224. });}
  225. catch(err){console.log(err);
  226. }
  227. }
  228. );
  229. }
  230. request.send();
  231. document.body.dispatchEvent(new MouseEvent('mousemove'));
  232. // modify this part
  233. // if(sites[hostname].background) {
  234. // document.body.style.background = sites[hostname].background;
  235. // document.body.style.overflow = 'scroll';
  236. // document.body.style.position = 'static';
  237. // }
  238.  
  239.  
  240. }
  241. let interval=null;
  242.  
  243. cleanup();
  244. if(interval === null) {
  245. interval = window.setInterval(function(){
  246. cleanup();
  247. }, 5000);
  248. }
  249.  
  250. })();
  251. //"ytd-display-ad-renderer"