FKCSDN

it's a script to blocked The CSDN website like https://www.csdn.net/ in most broswers because the website is so disgusting

  1. // ==UserScript==
  2. // @name FKCSDN
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.2
  5. // @description it's a script to blocked The CSDN website like https://www.csdn.net/ in most broswers because the website is so disgusting
  6. // @description 在大多数都主流浏览器中屏蔽了 CSDN 站点,所以起名 FKCSDN
  7. // @include *://www.baidu.com/*
  8. // @include *://www.dogedoge.com/*
  9. // @include *://www.so.com/*
  10. // @include *://www.sogou.com/*
  11. // @include *://www.google.com/*
  12. // @include *://duckduckgo.com/*
  13. // @include *.bing.com/*
  14.  
  15. // @grant none
  16. // ==/UserScript==
  17.  
  18.  
  19. (function() {
  20. 'use strict';
  21. var move = false
  22. var insertHtml = `
  23. <div style="" class="__fixed-btn">
  24. <div class="fk-box">
  25. <div class="fk-csdn">FK CSDN</div>
  26. <label class="fk-item">
  27. <input type="checkbox" name="fk-csdn" checked="true">
  28. <div class="slider round"></div>
  29. </label>
  30. </div>
  31. </div>`
  32.  
  33. var insertStyle = `<style type="text/css">
  34. .__fixed-btn {
  35. -webkit-user-select: none;
  36. position: fixed;
  37. top: 150px;
  38. left: 0;
  39. border-radius: 50px;
  40. width: 100px;
  41. height: 100px;
  42. background-color: #f2f8ff;
  43. z-index: 10000;
  44. }
  45.  
  46. .slider.round {
  47. border-radius: 34px;
  48. }
  49.  
  50. .slider {
  51. position: absolute;
  52. cursor: pointer;
  53. width: 40px;
  54. height: 20px;
  55. top: 0;
  56. left: 0;
  57. right: 0;
  58. bottom: 0;
  59. background-color: #ccc;
  60. -webkit-transition: .4s;
  61. transition: .4s;
  62. }
  63.  
  64. .slider.round:before {
  65. border-radius: 50%;
  66. }
  67.  
  68. .slider:before {
  69. position: absolute;
  70. content: "";
  71. height: 16px;
  72. width: 16px;
  73. left: 2px;
  74. bottom: 2px;
  75. background-color: white;
  76. -webkit-transition: .4s;
  77. transition: .4s;
  78. }
  79.  
  80. .fk-item input {
  81. display: none;
  82. }
  83.  
  84. .fk-item {
  85. position: absolute;
  86. right: 0;
  87. top: 10px;
  88. display: inline-block;
  89. vertical-align: middle;
  90. width: 40px;
  91. height: 20px;
  92. top: 6px;
  93. }
  94.  
  95. input:checked+.slider {
  96. background-color: #2196F3;
  97. }
  98.  
  99. input:checked+.slider:before {
  100. -webkit-transform: translateX(20px);
  101. -ms-transform: translateX(20px);
  102. transform: translateX(20px);
  103. }
  104.  
  105. .fk-csdn {
  106. color: #000;
  107. font-weight: bold;
  108. font-size: 12px;
  109. vertical-align: middle;
  110. }
  111.  
  112. .fk-box {
  113. position: relative;
  114. height: 30px;
  115. line-height: 30px;
  116. }
  117.  
  118. .fk-box:first-child {
  119. margin-top: 20px;
  120. }
  121. </style>
  122. `
  123. document.querySelector('body').insertAdjacentHTML('afterbegin', insertHtml);
  124. document.querySelector('head').insertAdjacentHTML('afterbegin', insertStyle);
  125.  
  126. var searchEngineCode = '00';
  127. var fixedBtn = document.querySelector('.__fixed-btn');
  128. var inputBox = document.querySelector('input[type=checkbox]');
  129. var searchBtn = document;
  130. var searchInput = document;
  131.  
  132. // 1 google 2 duck 3 baidu 4 sogo 5 360 6 doge 7 bing
  133. switch (window.location.host) {
  134. case 'www.google.com':
  135. searchEngineCode = '01';
  136. searchBtn = document.querySelector('.Tg7LZd');
  137. searchInput = document.querySelector('.gLFyf');
  138. break;
  139. case 'duckduckgo.com':
  140. searchEngineCode = '02';
  141. searchBtn = document.querySelector('#search_button');
  142. searchInput = document.querySelector('#search_form_input');
  143. break;
  144. case 'www.baidu.com':
  145. searchEngineCode = '03';
  146. searchBtn = document.querySelector('#su');
  147. searchInput = document.querySelector('#kw');
  148. document.querySelector('#wrapper').insertAdjacentHTML('afterbegin', insertStyle);
  149. break;
  150. case 'www.sogou.com':
  151. searchEngineCode = '04';
  152. searchBtn = document.querySelector('#searchBtn');
  153. searchInput = document.querySelector('#upquery');
  154. break;
  155. case 'www.so.com':
  156. searchEngineCode = '05';
  157. searchBtn = document.querySelector('#su');
  158. searchInput = document.querySelector('#keyword');
  159. break;
  160. case 'www.dogedoge.com':
  161. searchEngineCode = '06';
  162. searchBtn = document.querySelector('#search_button');
  163. searchInput = document.querySelector('#search_form_input');
  164. break;
  165. case 'cn.bing.com':
  166. searchEngineCode = '07';
  167. searchBtn = document.querySelector('#sb_form_go');
  168. searchInput = document.querySelector('#sb_form_q');
  169. break;
  170. case 'www.bing.com':
  171. searchEngineCode = '07';
  172. searchBtn = document.querySelector('#sb_form_go');
  173. searchInput = document.querySelector('#sb_form_q');
  174. break;
  175. default:
  176. searchEngineCode = '00';
  177. console.log('不支持此搜索引擎')
  178. break;
  179. }
  180.  
  181. var isChecked = window.localStorage.getItem('FKCSDNCheck') == 'false' ? false : true;
  182. inputBox.checked = isChecked;
  183.  
  184. var mouseDownClientX, mouseDownClientY, mouseDownOffsetLeft, mouseDownOffsetRight,mouseChangeClientX,mouseChangeClientY;
  185. var windowWidth = window.innerWidth,
  186. windowHeight = window.innerHeight
  187. fixedBtn.addEventListener("mousedown", function(e) {
  188. fixedBtn.style.transition = '';
  189. move = true;
  190. mouseDownClientX = e.clientX;
  191. mouseDownClientY = e.clientY;
  192. mouseDownOffsetLeft = fixedBtn.offsetLeft;
  193. mouseDownOffsetRight = fixedBtn.offsetTop;
  194. });
  195. document.addEventListener("mousemove", function(e) {
  196. if (move == false) {
  197. return;
  198. }
  199. var x = e.clientX;
  200. var y = e.clientY;
  201. fixedBtn.style.left = x - (mouseDownClientX - mouseDownOffsetLeft) + "px";
  202. fixedBtn.style.top = y - (mouseDownClientY - mouseDownOffsetRight) + "px";
  203. });
  204.  
  205. fixedBtn.addEventListener("mouseup", function(e) {
  206. move = false;
  207. mouseChangeClientX = e.clientX;
  208. mouseChangeClientY = e.clientY;
  209. fixedBtn.style.transition = 'all .3s';
  210. if(mouseChangeClientX < windowWidth/2){
  211. fixedBtn.style.left = 0;
  212. }else {
  213. fixedBtn.style.left = windowWidth - fixedBtn.clientWidth + 'px';
  214. }
  215. if(fixedBtn.offsetTop < 0){
  216. fixedBtn.style.top = 0;
  217. }else if(fixedBtn.offsetTop + fixedBtn.clientHeight > windowHeight) {
  218. fixedBtn.style.top = windowHeight- fixedBtn.clientHeight + 'px';
  219. }
  220. });
  221. inputBox.addEventListener('change', function() {
  222. var name = this.getAttribute('name');
  223. var value = this.getAttribute('checked');
  224. var ele = this;
  225. switch (name) {
  226. case 'fk-csdn':
  227. FKCSDN(name, value, ele);
  228. break
  229. case '':
  230. break;
  231. default:
  232. break;
  233. }
  234. })
  235. searchBtn && searchBtn.addEventListener('click', function(e) {
  236. if (searchEngineCode == '00') return;
  237. var searchText = searchInput.value;
  238. var searchArr = searchText.split(' ');
  239. var hasValue = false;
  240. for (var key in searchArr) {
  241. if (searchArr[key] == '-site:csdn.net') {
  242. hasValue = true;
  243. }
  244. }
  245. if (!hasValue && isChecked) {
  246. searchInput.value = searchText + ' -site:csdn.net';
  247. }
  248. })
  249.  
  250. function FKCSDN(name, value, ele) {
  251. if (searchEngineCode == '00') return;
  252. isChecked = ele.checked == true;
  253. window.localStorage.setItem('FKCSDNCheck', isChecked)
  254. if (!isChecked) {
  255. var searchText = searchInput.value;
  256. var searchArr = searchText.split(' ');
  257. var newArr = [];
  258. if (searchArr.includes('-site:csdn.net')) {
  259. searchArr.forEach((value, index) => {
  260. if (value !== '-site:csdn.net') {
  261. newArr.push(value);
  262. }
  263. })
  264. searchInput.value = newArr.join(' ');
  265. }
  266. }
  267. searchBtn.click();
  268.  
  269. }
  270.  
  271. })();

QingJ © 2025

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