HentaiCosplays

Viewer for HentaiCosplays

  1. // ==UserScript==
  2. // @name HentaiCosplays
  3. // @namespace http://tampermonkey.net/https://hentai-cosplays.com/search/
  4. // @version 0.1
  5. // @description Viewer for HentaiCosplays
  6. // @author You
  7. // @match https://hentai-cosplays.com/search/*
  8. // @match https://hentai-cosplays.com/ranking/*
  9. // @match https://hentai-cosplays.com/recently/*
  10. // @icon https://www.google.com/s2/favicons?sz=64&domain=hentai-cosplays.com
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_addStyle
  13. // @grant GM_getResourceText
  14. // @require https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.0/viewer.min.js
  15. // @resource viewerCSS https://cdnjs.cloudflare.com/ajax/libs/viewerjs/1.11.0/viewer.min.css
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. const DEBUG_INFO = false;
  21. const DEBUG_VERBOSE = false;
  22.  
  23. function debug_info(...data) { if (DEBUG_INFO === true) { console.log('[INFO] ', data); } }
  24. function debug_verbose(...data) { if (DEBUG_VERBOSE === true) { console.log('[VERBOSE]', data); } }
  25.  
  26. GM_addStyle(GM_getResourceText('viewerCSS'));
  27. const host = window.location.host;
  28. const old_image_container = document.querySelector('#center');
  29. const new_image_viewer = document.createElement('ul');
  30. new_image_viewer.setAttribute('id', 'imagesViewer'); // 注册新的图片浏览器
  31.  
  32. // 声明相册实例
  33. const gallery = new Viewer(new_image_viewer, {
  34. fullscreen: false,
  35. interval: 1200,
  36. loop: false,
  37. transition: false,
  38. });
  39.  
  40. old_image_container.appendChild(new_image_viewer); // 注入图片浏览器
  41. const image_list = document.getElementById('image-list').getElementsByTagName('a')
  42.  
  43. var last_clicked_img = '';
  44.  
  45. for(let i = 0; i < image_list.length; i+=2) {
  46. image_list[i].onclick = function() {
  47. let img_href = this.getAttribute('href');
  48. debug_info('click ' + img_href);
  49. if(last_clicked_img !== img_href) { // 不刷新 imagesViewer 的 ul
  50. new_image_viewer.innerHTML = '';
  51. gallery.update();
  52. last_clicked_img = img_href;
  53.  
  54. const img_story_url = 'https://' + host + img_href.replace('/image/', '/story/');
  55. debug_info('fetch ' + img_story_url);
  56.  
  57. GM_xmlhttpRequest({
  58. url: img_story_url,
  59. method: 'GET',
  60. onload: (xhr) => {
  61. let data = xhr.response;
  62. let htmlDoc = new DOMParser().parseFromString(data, 'text/html');
  63. const img_count = htmlDoc.getElementsByTagName("amp-story-page").length;
  64.  
  65. var img_prefix = htmlDoc.querySelector("meta[property='og:image']").getAttribute("content");
  66. img_prefix = img_prefix.slice(0, img_prefix.lastIndexOf('/')+1);
  67.  
  68. for(let i = 1; i <= img_count; i++) {
  69. let img_element = document.createElement('img');
  70. img_element.setAttribute("src", img_prefix + i + ".jpg")
  71. img_element.setAttribute("hidden", "hidden");
  72. new_image_viewer.appendChild(img_element);
  73. }
  74. gallery.update();
  75. }
  76. });
  77. }
  78.  
  79. gallery.show();
  80. return false;
  81. }
  82. }
  83.  
  84. })();