SCP Artwork Hub Show Image

Show Image For SCP Artwork Hub .

当前为 2022-01-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @namespace https://greasyfork.org/zh-TW/users/142344-jasn-hr
  3. // @name SCP Artwork Hub Show Image
  4. // @description Show Image For SCP Artwork Hub .
  5. // @copyright 2022, HrJasn (https://greasyfork.org/zh-TW/users/142344-jasn-hr)
  6. // @license GPL-3.0-or-later
  7. // @version 1.1
  8. // @icon https://www.google.com/s2/favicons?domain=wikidot.com
  9. // @include http*://*scp*.wikidot.com/*art*
  10. // @include http://ko.scp-wiki.net/scp-artwork-hub-ko
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. window.onload = function(){
  15.  
  16. const ArtImageWindow = document.body.appendChild(document.createElement('img'));
  17. ArtImageWindow.style = 'position:fixed;right:5px;bottom:5px;border:0px;max-height:20%;max-width:20%;background-color:white;';
  18. ArtImageWindow.style.display = 'none';
  19. ArtImageWindow.addEventListener('mouseleave',function(e){
  20. ArtImageWindow.style.display = 'none';
  21. ArtImageWindow.style.right = '0px';
  22. ArtImageWindow.style.bottom = '0px';
  23. ArtImageWindow.src = '';
  24. });
  25.  
  26. const loadImage = function(e){
  27. e.target.style.cursor = 'wait';
  28. let fetchURL = e.target.href;
  29. fetchURL = fetchURL.replace(/^(https?:\/\/[^\/]+\/adult:.*)$/,"$1/noredirect/true");
  30. fetch(fetchURL,{method:'GET',}).then(function(res){
  31. return res.text();
  32. }).then(function(resText){
  33. let parser = new DOMParser();
  34. let resDom = parser.parseFromString(resText,"text/html");
  35. let resDomBody = resDom.body;
  36. let ArtworkImage = resDomBody.querySelector('#page-content div.image-container img') ||
  37. resDomBody.querySelector('#page-content img.image:not([src="http://scp-jp.wikidot.com/local--files/nav:side/blank.png"]):not([src="http://scp-idn.wdfiles.com/local--files/shaun159-pixel-artpage/ball.jpg"])') ||
  38. resDomBody.querySelector('#page-content img.fillpg');
  39. let ArtworkImageSrc = ArtworkImage.src;
  40. ArtImageWindow.src = ArtworkImageSrc;
  41. let newright = window.innerWidth - e.clientX;
  42. let newbottom = window.innerHeight - e.clientY;
  43. ArtImageWindow.style.right = newright + 'px';
  44. ArtImageWindow.style.bottom = newbottom + 'px';
  45. ArtImageWindow.style.display = '';
  46. e.target.style.cursor = 'auto';
  47. });
  48. }
  49.  
  50. const moveImage = function(e){
  51. let newright = window.innerWidth - e.clientX;
  52. let newbottom = window.innerHeight - e.clientY;
  53. ArtImageWindow.style.right = newright + 'px';
  54. ArtImageWindow.style.bottom = newbottom + 'px';
  55. }
  56.  
  57. const takeoutImage = function(e){
  58. ArtImageWindow.style.display = 'none';
  59. ArtImageWindow.style.right = '0px';
  60. ArtImageWindow.style.bottom = '0px';
  61. ArtImageWindow.src = '';
  62. }
  63.  
  64. let divContents = [
  65. document.querySelectorAll('div.content-type-description tr'),
  66. document.querySelectorAll('div.content-type-description-2 tr')
  67. ]
  68. let divContentTypeDescriptionTrs = divContents.reduce(function(a, b){return a.length > b.length ? a : b ;});
  69. for(let i=0;i<divContentTypeDescriptionTrs.length;i++){
  70. let artworkLinkOBJ = divContentTypeDescriptionTrs[i].querySelector('td:first-child a');
  71. console.log(artworkLinkOBJ);
  72. if(artworkLinkOBJ){
  73. artworkLinkOBJ.addEventListener('mouseenter',loadImage);
  74. artworkLinkOBJ.addEventListener('mousemove',moveImage);
  75. artworkLinkOBJ.addEventListener('mouseleave',takeoutImage);
  76. }
  77. }
  78.  
  79. }