Greasy Fork is available in English.

【自用】直接跳转图片 - netbian.com

7/19/2021, 7:13:46 PM

  1. // ==UserScript==
  2. // @icon https://github.com/favicon.ico
  3. // @name 【自用】直接跳转图片 - netbian.com
  4. // @namespace Violentmonkey Scripts
  5. // @match http://www.netbian.com/desk/*.htm
  6. // @Update URL https://greasyfork.org/zh-CN/scripts/429609/versions/new
  7. // @grant none
  8. // @version 2021.10.28
  9. // @author -
  10. // @description 7/19/2021, 7:13:46 PM
  11. // ==/UserScript==
  12.  
  13. function addNewStyle(newStyle) {//增加新样式表
  14. var styleElement = document.getElementById('styles_js');
  15. if (!styleElement) {
  16. styleElement = document.createElement('style');
  17. styleElement.type = 'text/css';
  18. styleElement.id = 'styles_js';
  19. document.getElementsByTagName('head')[0].appendChild(styleElement);
  20. }
  21. styleElement.appendChild(document.createTextNode(newStyle));
  22. }
  23.  
  24. const cssa =`
  25. .wrap,#header {z-index:0 !important;}
  26. #login_opacity_bg {height:0px !important;} /*登录提示隐藏*/
  27. div.tbox {height:0px !important;} /*登录提示隐藏*/
  28. `
  29.  
  30. addNewStyle(cssa);
  31.  
  32.  
  33. //*绑定事件*/
  34. function addEvent(obj, sType, fn) {
  35. if (obj.addEventListener) {
  36. obj.addEventListener(sType, fn, false);
  37. } else {
  38. obj.attachEvent('on' + sType, fn);
  39. }
  40. };
  41. function removeEvent(obj, sType, fn) {
  42. if (obj.removeEventListener) {
  43. obj.removeEventListener(sType, fn, false);
  44. } else {
  45. obj.detachEvent('on' + sType, fn);
  46. }
  47. };
  48. function prEvent(ev) {
  49. var oEvent = ev || window.event;
  50. if (oEvent.preventDefault) {
  51. oEvent.preventDefault();
  52. }
  53. return oEvent;
  54. }
  55. //*添加滑轮事件*/
  56. function addWheelEvent(obj, callback) {
  57. if (window.navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
  58. addEvent(obj, 'DOMMouseScroll', wheel);
  59. } else {
  60. addEvent(obj, 'mousewheel', wheel);
  61. }
  62. function wheel(ev) {
  63. var oEvent = prEvent(ev),
  64. delta = oEvent.detail ? oEvent.detail > 0 : oEvent.wheelDelta < 0;
  65. callback && callback.call(oEvent, delta);
  66. return false;
  67. }
  68. };
  69.  
  70. /*页面载入后*/
  71. window.onload = function () {
  72. var oImg = document.getElementById('pic_xx_img'); //【【】【】【】【此处自己改】【】【】【】【】】
  73. /*拖拽功能*/
  74. (function () {
  75. addEvent(oImg, 'mousedown', function (ev) {
  76. var oEvent = prEvent(ev),
  77. oParent = oImg.parentNode,
  78. disX = oEvent.clientX - oImg.offsetLeft,
  79. disY = oEvent.clientY - oImg.offsetTop,
  80. startMove = function (ev) {
  81. if (oParent.setCapture) {
  82. oParent.setCapture();
  83. }
  84. var oEvent = ev || window.event,
  85. l = oEvent.clientX - disX,
  86. t = oEvent.clientY - disY;
  87. oImg.style.left = l + 'px';
  88. oImg.style.top = t + 'px';
  89. oParent.onselectstart = function () {
  90. return false;
  91. }
  92. },
  93. endMove = function (ev) {
  94. if (oParent.releaseCapture) {
  95. oParent.releaseCapture();
  96. }
  97. oParent.onselectstart = null;
  98. removeEvent(oParent, 'mousemove', startMove);
  99. removeEvent(oParent, 'mouseup', endMove);
  100. };
  101. addEvent(oParent, 'mousemove', startMove);
  102. addEvent(oParent, 'mouseup', endMove);
  103. pic_xx.style.transitionDuration = "0s";//缩放时过渡关了,要不不跟手
  104. return false;
  105. });
  106. })();
  107. //*以鼠标位置为中心的滑轮放大功能*/
  108. (function () {
  109. addWheelEvent(oImg, function (delta) {
  110. var img = new Image(); // 创建一个新的img,不过也不设定属性,相当于一个备份,后台应该是加载了,会有img.width产生,而且不操作它,因此是个定量 //这里得重新定义一个
  111. img.src = oImg.src;
  112. var ratioL = (this.clientX - oImg.offsetLeft) / oImg.offsetWidth,
  113. ratioimg = oImg.width / oImg.height, //!!!这里是自己修改的,限定最小缩放
  114. ratioT = (this.clientY - oImg.offsetTop) / oImg.offsetHeight,
  115. ratioDelta = !delta ? 1 + 0.1 : 1 - 0.1,
  116. w = Math.max(parseInt(oImg.offsetWidth * ratioDelta), 0.5 * screen.width), //!!!这里是自己修改的,限定最小缩放
  117. h = Math.max(parseInt(oImg.offsetHeight * ratioDelta), 0.5 * screen.width/ratioimg), //!!!这里是自己修改的,限定最小缩放
  118. l = Math.round(this.clientX - (w * ratioL)),
  119. t = Math.round(this.clientY - (h * ratioT));
  120. with (oImg.style) {
  121. width = w + 'px';
  122. height = h + 'px';
  123. left = l + 'px';
  124. top = t + 'px';
  125. var pct = (w/img.width*100).toFixed(0);
  126. btn100.innerHTML = pct + "%";
  127. pic_xx.style.transitionDuration = "0s";//缩放时过渡关了,要不不跟手
  128. }
  129.  
  130. });
  131. })();
  132. };
  133.  
  134.  
  135.  
  136. //===================================看图相关============================================
  137. var grey_bg = document.createElement("div"); //创建一个DIV用来当透明背景
  138. grey_bg.setAttribute("Id", "grey_bg_div"); //定灰背景的ID
  139. var imgbox_s = document.createElement("div"); //创建装预览图的div,必须得有个div做fixed的容器,要不滚轮就往下翻页了
  140. var pic_xxs = document.createElement("img"); //创建预览图img
  141. imgbox_s.setAttribute("Id", "imgbox_s_div"); //定预览图的div的ID
  142. pic_xxs.setAttribute("Id", "pic_xx_img_s"); //定预览图的ID
  143. var imgbox = document.createElement("div"); //创建装原图片的div
  144. var pic_xx = document.createElement("img"); //创建原图img
  145. imgbox.setAttribute("Id", "imgbox_div"); //定原图片的div的ID
  146. pic_xx.setAttribute("Id", "pic_xx_img"); //定原图的ID
  147.  
  148. document.body.appendChild(grey_bg); //灰背景加到页面
  149. document.getElementById("grey_bg_div").appendChild(imgbox_s); //预览图的div层加到透明背景
  150. document.getElementById("imgbox_s_div").appendChild(pic_xxs); //预览图加到div里
  151. document.getElementById("grey_bg_div").appendChild(imgbox); //原图的div层加到透明背景
  152. document.getElementById("imgbox_div").appendChild(pic_xx); //原图加到透明背景
  153.  
  154. //下面给灰背景加属性,默认高度0来隐藏,转移符后面不能乱加空格
  155. grey_bg.style.cssText = "position:fixed;\
  156. top:0px;\
  157. left:0px;\
  158. width:100%;\
  159. height:0px;\
  160. background-color: rgb(0, 0, 0, 0.8);\
  161. text-align:center;\
  162. padding:0;\
  163. margin:0;\
  164. vertical-align:middle;"; //定CSS
  165.  
  166. imgbox_s.style.cssText = "top:0px;left:0px;padding:0px;"; //padding缩边,margin是扩,但后续因为还有一个div,这里直接就设成0
  167.  
  168. function img_prev(a) { //【当前页面打开图片】后面添加到每一个链接
  169. grey_bg.style.height = "100%";//开灰背景
  170.  
  171. imgbox_s.style.height = "100%";//开预览图div
  172. imgbox.style.height = "0";//关大图div
  173. pic_xxs.style.cssText = "padding:20px !important;height:100%;box-sizing:border-box;";//开预览图
  174. pic_xxs.setAttribute("src", a.getAttribute("href"));//设定链接
  175. return; //这里得加,要不drag运行后,都变成false了
  176. }
  177.  
  178. function close_prev() { //【关闭打开的图片】点击非图片部分
  179. grey_bg.style.height = "0%"; //关闭灰背景
  180. pic_xxs.style.height = "0px"; //关闭预览
  181. pic_xxs.setAttribute("src", ""); //清空缓存,要不刚点开还是上次加载的图片
  182. pic_xx.style.height = "0px"; //关闭原图
  183. pic_xx.setAttribute("src", ""); //清空缓存,要不刚点开还是上次加载的图片
  184. imgbox_s.style.width = "100%"; //恢复宽度
  185. spancl.style.display = "none";//显示关闭按钮
  186. current = 0;
  187. btnrt.style.display = "none";//显示
  188. btn100.style.display = "none";//显示
  189. pic_xx.style.transitionDuration = "0s";//缩放时过渡关了,要不不跟手
  190. }
  191.  
  192. function full_view() { //【100%大小,可拖动】
  193. event.stopPropagation(); //!!!!!!!!不加这个,会穿透到父元素的事件!!!!!
  194. var img_url = document.getElementById("pic_xx_img_s").src;// + "?" + Date.parse(new Date()); //重构地址 //看来没必要加随机后缀,有的网站不知道是不是防外链,重构就无法加载例如DA和wallhaven
  195. var imghid = new Image(); // 创建一个新的img,不过也不设定属性,相当于一个备份,后台应该是加载了,会有img.width产生,而且不操作它,因此是个定量
  196. imghid.src = img_url;
  197. var le = 0.5 * (window.innerWidth - imghid.width);
  198. var to = 0.5 * (window.innerHeight - imghid.height);
  199. imgbox_s.style.height = "0";//关预览图div
  200. imgbox.style.height = "100%";//关预览图div
  201. imgbox.style.position = "fixed";//关预览图div
  202. pic_xxs.style.height = "0"; //关预览图
  203. pic_xx.style.height = ""; //开预览图
  204. pic_xx.setAttribute("src", img_url);//预览图地址
  205. pic_xx.style.cssText = "box-shadow: 0px 2px 6px rgba(0,0,0,0.12), 0px 1px 2px rgba(0,0,0,0.24) !important;\
  206. position:absolute;top:" + to + "px;left:" + le + "px;z-index:99;";
  207. imgbox_s.style.width = "0px"; //这里不清零,后面drag函数运行后图片初始靠右了
  208. spancl.style.display = "block";//显示关闭按钮
  209. btnrt.style.display = "block";//显示
  210. btn100.style.display = "block";//显示
  211. return false;//阻止默认,注意这里只阻止了点击pic_xxs的默认事件
  212. }
  213.  
  214. grey_bg.onclick = close_prev; //点击关闭
  215. pic_xxs.onclick = full_view; //点击看100%大小
  216. pic_xx.onclick = function(){event.stopPropagation();}; //单独设定阻止默认,不能放到上面那个函数里面,不知道为什么,多层触发?
  217.  
  218. //===================================备份链接、替换链接============================================
  219. var dir_links = "div#main div.endpage div.pic p a"; //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  220. var anchors = document.querySelectorAll(dir_links); //用CSS选择器获取目标链接
  221. var linkbak = "";
  222. for (i = 0; i < anchors.length; i++) {
  223. linkbak += "<a href=" + anchors[i] + ">" + i + "</a>" + "<br>"; //+=两个符号不能分开
  224. } //把原链接重构一下,变相的深拷贝,后续直接写入html不会出现object NodeList
  225.  
  226. var divbak = document.createElement("div"); //创建一个DIV用来储存链接
  227. divbak.setAttribute("Id", "baklink"); //定ID
  228. //document.getElementById("wrapper").appendChild(btn);
  229. document.body.appendChild(divbak); //div加到页面最后
  230. divbak.style.cssText = "position:fixed;top:500px;left:0px; display:none; "; //改DIV的位置,然后隐藏一下 display:none;
  231.  
  232. for (var i = 0; i < anchors.length; i++) {
  233. var dirimg_links = document.querySelectorAll("div#main div.endpage div.pic p a img");
  234. anchors[i].href = dirimg_links[i].src; //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  235. anchors[i].target = "_blank";
  236. anchors[i].onclick = function() {
  237. img_prev(this);
  238. return false;
  239. }; //添加函数
  240. } //.replace替换.slice修剪,最后加一个后缀,新标签页打开 //这里开始修改目标链接
  241. var linkbakQ = "";
  242. for (i = 0; i < anchors.length; i++) {
  243. linkbakQ += "<a href=" + anchors[i] + ">" + [i + anchors.length] + "</a>" + "<br>"; //[i+anchors.length]必须用中括号,要不当成字符串相加了
  244. } //把原链接重构一下,变相的深拷贝,后续直接写入html不会出现object NodeList
  245. divbak.innerHTML = linkbak + linkbakQ; //把链接写到新建的DIV中 !!这里的位置是在修改原链接之后,也没事,证明之前重构成功了
  246. var backedlink = document.querySelectorAll("div#baklink a"); //获取储存的链接, !!!注意必须得重新获取,直接用会是undefine
  247.  
  248. function reslink() {
  249. for (var i = 0; i < anchors.length; i++) {
  250. anchors[i].href = backedlink[i].href; //
  251. }
  252. }; //定义恢复链接的函数
  253.  
  254. function writelink() {
  255. for (var i = 0; i < anchors.length; i++) {
  256. anchors[i].href = backedlink[i + anchors.length].href; //
  257. }
  258. }; //定义重写链接的函数
  259.  
  260.  
  261. var spancl = document.createElement("span"); //创建一个按钮
  262. spancl.setAttribute("Id", "spancl"); //定义按钮ID
  263. document.body.appendChild(spancl); //把按钮加到页面
  264. spancl.style.cssText = "cursor: pointer;\
  265. position: fixed;\
  266. right: 0px;\
  267. top: 0px;\
  268. width: 46px;\
  269. background: url(\"data: image / png;base64, iVBORw0KGgoAAAANSUhEUgAAAC4AAAARCAIAAAAt9wkYAAA\
  270. AGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAA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gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI / PmUW1owAAADqSURBVHja5FWxCoQwDL2W + x\
  282. 4X / QmHujvXzV0XadHN31HUn2gR / KD2AgWRAytETpTLEF5eSfqaaEvyPH / dw97W2rtIMcY8uytKKQeiKPKTP5fSdZ0DSZKE\
  283. YQhAa72SdV0japIsy3D9XPdjjIHv + 96FUkpPFqV0VwrnHD3dpmm + GCHEwdEJ2VVpTlhVVdtaEB6m2H2j9oTN87yVAuFhikcl\
  284. viuw8TAMWykQAonuCvJeWZZlmiaHy7IE37Yt + HEc4zgOggBREzmgVUdRFI4B4BhYwg2IpGl65ZXq + ZmvfoM838MfP4fPGNBH\
  285. gAEAi7gyuvHuhZcAAAAASUVORK5CYII =\") no-repeat center bottom;\
  286. height: 17px;\
  287. opacity: 0.9;\
  288. border: none;\
  289. padding: 0;\
  290. padding-top: 0px;\
  291. background-color: #1771FF;\
  292. display:none;\
  293. z-index:9999999999999999999999999999";
  294. spancl.onclick = close_prev;//点击关闭
  295.  
  296.  
  297.  
  298.  
  299.  
  300. var btnstyle = "border: none !important;\
  301. width:60px;\
  302. font-size: 12px !important;\
  303. font-weight: 200 !important;\
  304. letter-spacing: 0em !important;\
  305. line-height: 0em !important;\
  306. height:24px !important;\
  307. display: inline-block;\
  308. outline: 0 !important;\
  309. padding: 3px 12px !important;\
  310. margin-top: 15px !important;\
  311. margin-bottom: 10px !important;\
  312. vertical-align: middle !important;\
  313. overflow: hidden !important;\
  314. text-decoration: none !important;\
  315. color: #fff !important;\
  316. text-align: center !important;\
  317. transition: .2s ease-out !important;\
  318. cursor: pointer !important;\
  319. white-space: nowrap !important;\
  320. box-shadow: 0px 2px 6px rgba(0,0,0,0.12), 0px 1px 2px rgba(0,0,0,0.24) !important;\
  321. border-radius:0px !important;\
  322. opacity:0.3;";
  323. //定义按钮的CSS
  324.  
  325. function align100(){// 加载完成执行
  326. var img_url = document.getElementById("pic_xx_img_s").src;// + "?" + Date.parse(new Date()); //重构地址 //看来没必要加随机后缀,有的网站不知道是不是防外链,重构就无法加载例如DA和wallhaven
  327. var img = new Image(); // 创建一个新的img,不过也不设定属性,相当于一个备份,后台应该是加载了,会有img.width产生,而且不操作它,因此是个定量
  328. img.src = img_url;
  329. var le = 0.5*(window.innerWidth - img.width);
  330. var to = 0.5*(window.innerHeight - img.height);
  331. pic_xx.style.cssText = "box-shadow: 0px 2px 6px rgba(0,0,0,0.12), 0px 1px 2px rgba(0,0,0,0.24) !important;position:absolute;z-index:2;left:"+le+"px;top:"+to+"px;";
  332. btn100.innerHTML = "100%";
  333. current = 0;
  334. }
  335.  
  336. var btn100 = document.createElement("button"); //创建一个按钮
  337. btn100.setAttribute("Id", "btn100"); //定义按钮ID
  338. document.body.appendChild(btn100); //把按钮加到页面
  339. btn100.style.cssText = "z-index:1;position:fixed;top:460px;left:20px;background-color: #2D8CF0;display:none !important;" + btnstyle; //改变按钮位置
  340. btn100.onmouseover = function(){btn100.style.opacity = "1";}
  341. btn100.onmouseout = function(){btn100.style.opacity = "0.3";}
  342. btn100.innerHTML = "100%"; //按钮文本
  343. btn100.onclick = align100; //给按钮加函数
  344.  
  345.  
  346.  
  347. var btnrt = document.createElement("button"); //创建一个按钮
  348. btn100.setAttribute("Id", "btnrt"); //定义按钮ID
  349. document.body.appendChild(btnrt); //把按钮加到页面
  350. btnrt.style.cssText = "z-index:1;position:fixed;top:420px;left:20px;background-color: #FC5531;display:none !important;" + btnstyle; //改变按钮位置
  351. btnrt.onmouseover = function(){btnrt.style.opacity = "1";}
  352. btnrt.onmouseout = function(){btnrt.style.opacity = "0.3";}
  353. btnrt.innerHTML = "右转"; //按钮文本
  354. var current = 0;//这里必须赋值,还得在函数外面
  355. btnrt.onclick =function rotate90(){
  356. current = current + 90;
  357. pic_xx.style.transform = 'rotate('+ current +'deg)';
  358. pic_xx.style.transitionDuration = "0.3s";//加一个过渡,没那么楞
  359. }
  360.  
  361.  
  362. var btnre = document.createElement("button"); //创建一个按钮
  363. btnre.setAttribute("Id", "btnre"); //定义按钮ID
  364. document.body.appendChild(btnre); //把按钮加到页面
  365. btnre.style.cssText = "position:fixed;z-index:0;top:500px;left:20px;background-color: #1EA362;" + btnstyle; //改变按钮位置,z-index取负值能在greylayer下面
  366. btnre.innerHTML = "恢复"; //按钮文本
  367. btnre.onclick = reslink; //给按钮加函数
  368. btnre.onmouseover = function(){btnre.style.opacity = "1";}
  369. btnre.onmouseout = function(){btnre.style.opacity = "0.3";}
  370.  
  371. var btnwr = document.createElement("button"); //创建一个按钮
  372. btnwr.setAttribute("Id", "btnwr"); //定义按钮ID
  373. document.body.appendChild(btnwr); //把按钮加到页面
  374. btnwr.style.cssText = "position:fixed;z-index:0;top:540px;left:20px;background-color: #e9686b;" + btnstyle; //改变按钮位置,z-index取负值能在greylayer下面
  375. btnwr.innerHTML = "重写"; //按钮文本
  376. btnwr.onclick = writelink; //给按钮加函数
  377. btnwr.onmouseover = function(){btnwr.style.opacity = "1";}
  378. btnwr.onmouseout = function(){btnwr.style.opacity = "0.3";}