点击删除

在页面加载一个悬浮窗,双击后可以任意消除网页内的元素,包括广告等,不会影响网页的原本功能。

目前為 2019-05-09 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 点击删除
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5
  5. // @description 在页面加载一个悬浮窗,双击后可以任意消除网页内的元素,包括广告等,不会影响网页的原本功能。
  6. // @author Huangfu
  7. // @include *
  8. // @grant none
  9. // ==/UserScript==
  10. (function(){
  11. 'use strict';
  12. var deleteMode = 0;
  13. if(self != top) return;//不要再iframe里再加载一次
  14. var new_element_N=document.createElement("style");
  15. new_element_N.innerHTML = '#drager {' +
  16. ' position: fixed;' +
  17. ' width: 35px;' +
  18. ' height: 35px;' +
  19. ' background-color: rgba(0, 0, 0, 0.2);' +
  20. ' z-index: 10000;' +
  21. ' cursor: pointer;' +
  22. ' top: 0px;' +
  23. ' left: 0px;' +
  24. ' border-radius: 30%;' +
  25. ' padding: 6px;' +
  26. ' }' +
  27. ' ' +
  28. ' #drager>div {' +
  29. ' border-radius: 50%;' +
  30. ' width: 100%;' +
  31. ' height: 100%;' +
  32. ' background-color: rgba(0, 0, 0, 0.3);' +
  33. ' transition: all 0.2s;' +
  34. ' -webkit-transition: all 0.2s;' +
  35. ' -moz-transition: all 0.2s;' +
  36. ' -o-transition: all 0.2s;' +
  37. ' }' +
  38. ' #drager:hover>div{' +
  39. ' background-color: rgba(0, 0, 0, 0.6);' +
  40. ' } '+
  41. '.chosenBorder{border:1px solid #00F;} ';
  42. document.body.appendChild(new_element_N);
  43. new_element_N=document.createElement('div');
  44. new_element_N.setAttribute("id","drager");
  45. new_element_N.style.top="80px";
  46. new_element_N.style.left = (document.body.clientWidth-45)+"px";
  47. new_element_N.innerHTML = ' <div></div>' ;
  48. document.body.appendChild(new_element_N);
  49. //
  50. var posX;
  51. var posY;
  52. var screenWidth =document.documentElement.clientWidth;
  53. var screenHeight = document.documentElement.clientHeight;
  54. var fdiv = document.getElementById("drager");
  55. fdiv.onmousedown=function(e)
  56. {
  57. screenWidth =document.documentElement.clientWidth;
  58. screenHeight = document.documentElement.clientHeight;
  59. if(!e){ e = window.event; } //IE
  60. posX = e.clientX - parseInt(fdiv.style.left);
  61. posY = e.clientY - parseInt(fdiv.style.top);
  62. document.onmousemove = mousemove;
  63. }
  64. document.onmouseup = function()//释放时自动贴到最近位置
  65. {
  66. document.onmousemove = null;
  67. if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenHeight/2)){//在上半部分
  68. if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)){//在左半部分
  69. if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)){//靠近上方
  70. fdiv.style.top="0px";
  71. }else{//靠近左边
  72. fdiv.style.left="0px";
  73. }
  74. }else{//在右半部分
  75. if((parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2)<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ){//靠近上方
  76. fdiv.style.top="0px";
  77. }else{//靠近右边
  78. fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";
  79. }
  80. }
  81. }else{ //下半部分
  82. if((parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)<=(screenWidth/2)){//在左半部分
  83. if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)){//靠近下方
  84. fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";
  85. }else{//靠近左边
  86. fdiv.style.left="0px";
  87. }
  88. }else{//在右半部分
  89. if( (screenHeight-(parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight)/2))<=(screenWidth-(parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth)/2)) ){//靠近上方
  90. fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";
  91. }else{//靠近右边
  92. fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";
  93. }
  94. }
  95. }
  96. }
  97. function mousemove(ev)
  98. {
  99. if(ev==null){ ev = window.event;}//IE
  100. if((ev.clientY - posY)<=0){//超过顶部
  101. fdiv.style.top="0px";
  102. }else if((ev.clientY - posY) >(screenHeight-parseInt(fdiv.clientHeight))){//超过底部
  103. fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";
  104. }else{
  105. fdiv.style.top = (ev.clientY - posY) + "px";
  106. }
  107. if((ev.clientX- posX)<=0){//超过左边
  108. fdiv.style.left="0px";
  109. }else if((ev.clientX - posX) >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边
  110. fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";
  111. }else{
  112. fdiv.style.left = (ev.clientX - posX) + "px";
  113. }
  114. // console.log( posX +" "+ fdiv.style.left);
  115. }
  116. window.onload = window.onresize = function() { //窗口大小改变事件
  117. screenWidth =document.documentElement.clientWidth;
  118. screenHeight = document.documentElement.clientHeight;
  119. if( (parseInt(fdiv.style.top)+parseInt(fdiv.clientHeight))>screenHeight){//窗口改变适应超出的部分
  120. fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";
  121. }
  122. if( (parseInt(fdiv.style.left)+parseInt(fdiv.clientWidth))>screenWidth){//窗口改变适应超出的部分
  123. fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";
  124. }
  125. document.onmouseup.apply()
  126. };
  127. fdiv.addEventListener('touchstart', fdiv.onmousedown, false);
  128. fdiv.addEventListener('touchmove', function(event) {
  129. // 如果这个元素的位置内只有一个手指的话
  130. if (event.targetTouches.length == 1) {
  131.      event.preventDefault();// 阻止浏览器默认事件,重要
  132. var touch = event.targetTouches[0];
  133. if((touch.pageY)<=0){//超过顶部
  134. fdiv.style.top="0px";
  135. }else if(touch.pageY>(screenHeight-parseInt(fdiv.clientHeight))){//超过底部
  136. fdiv.style.top=(screenHeight-parseInt(fdiv.clientHeight))+"px";
  137. }else{
  138. fdiv.style.top = (touch.pageY-parseInt(fdiv.clientHeight)/2) + "px";
  139. }
  140. if(touch.pageX<=0){//超过左边
  141. fdiv.style.left="0px";
  142. }else if( touch.pageX >(screenWidth-parseInt(fdiv.clientWidth))){//超过右边
  143. fdiv.style.left=(screenWidth-parseInt(fdiv.clientWidth))+"px";
  144. }else{
  145. fdiv.style.left = (touch.pageX-parseInt(fdiv.clientWidth)/2) + "px";
  146. }
  147. }
  148. }, false);
  149. fdiv.addEventListener('touchend', document.onmouseup , false);
  150. if (typeof(jQuery) == 'undefined'||$("drager").on==undefined) {
  151. let script = document.createElement('script');
  152. script.setAttribute('src', 'https://code.jquery.com/jquery-3.1.1.min.js');
  153. document.getElementsByTagName('head')[0].appendChild(script);
  154. }
  155. fdiv.ondblclick=function(){//双击事件可能在手机端浏览器会与网页缩放事件冲突
  156. if(deleteMode==0){//进入删除模式
  157. deleteMode = 1;
  158. //加边框知道选中了哪个
  159. $("*").hover(
  160. function(event){
  161. if(deleteMode==1){
  162. if(event.currentTarget.id=="drager"||event.currentTarget.parentNode.id=="drager") return false;
  163. $(this).addClass("chosenBorder");
  164. return false;
  165. }
  166. },
  167. function(){
  168. if(deleteMode==1){
  169. $(this).removeClass("chosenBorder");
  170. }
  171. }
  172. );
  173. //点击隐藏,使用on方法,保留原来的事件
  174. $("*").on("click",function (event){
  175. if(event.currentTarget.id=="drager"||event.currentTarget.parentNode.id=="drager") return false;
  176. $(this).hide();
  177. return false;
  178. });
  179. //单独操作iframe里的广告
  180. $("iframe").each(function(){
  181. //console.log($(this).attr("id"));
  182. $(window.frames[$(this).attr("id")].document).find("*").on("click",function (event){
  183. if(event.currentTarget.id=="drager"||event.currentTarget.parentNode.id=="drager") return false;
  184. $(this).hide();
  185. return false;
  186. });
  187. })
  188. }else{//删除结束
  189. deleteMode = 0;
  190. //去掉点击事件
  191. $("*").off("click");
  192. $(window.frames[$(this).attr("id")].document).find("*").off("click");
  193. }
  194. }
  195. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址