WebHelper

Add some useful features to some websites.

目前为 2022-06-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WebHelper
  3. // @name:vi WebHelper
  4. // @namespace https://lelinhtinh.github.io
  5. // @description Add some useful features to some websites.
  6. // @description:vi Bổ sung một số tính năng hữu ích cho một vài trang web.
  7. // @version 1.1.1
  8. // @icon https://i.imgur.com/FHgT0E4.png
  9. // @author Zzbaivong
  10. // @oujs:author baivong
  11. // @license MIT; https://baivong.mit-license.org/license.txt
  12. // @match https://tienhieptruyen.net/*
  13. // @require https://unpkg.com/hotkeys-js/dist/hotkeys.min.js
  14. // @noframes
  15. // @supportURL https://github.com/lelinhtinh/Userscript/issues
  16. // @run-at document-idle
  17. // @grant none
  18. // @inject-into content
  19. // ==/UserScript==
  20.  
  21. /* global hotkeys */
  22. const k = hotkeys.noConflict();
  23.  
  24. const chapter = document.querySelector('.chapter-c');
  25. chapter.scrollIntoView();
  26.  
  27. document.querySelector('.chap-content').style.userSelect = 'auto';
  28. chapter.querySelectorAll('[style]').forEach((e) => {
  29. e.remove();
  30. });
  31. document.addEventListener(
  32. 'contextmenu',
  33. function (event) {
  34. event.stopPropagation();
  35. },
  36. true,
  37. );
  38.  
  39. let lineHeight = parseFloat(getComputedStyle(chapter).lineHeight);
  40. document.querySelector('.chap-list-update .font-size').addEventListener('change', () => {
  41. setTimeout(() => {
  42. lineHeight = parseFloat(getComputedStyle(chapter).lineHeight);
  43. }, 100);
  44. });
  45.  
  46. let endChapter = false;
  47.  
  48. k('left', () => {
  49. document.querySelector('.chap-header .btn-next .fa-angle-double-left').parentNode.click();
  50. });
  51. k('right', () => {
  52. document.querySelector('.chap-header .btn-next .fa-angle-double-right').parentNode.click();
  53. });
  54.  
  55. k('up', () => {
  56. document.documentElement.scrollTop -= window.innerHeight - lineHeight * 2;
  57. });
  58. k('down', () => {
  59. if (endChapter) {
  60. k.trigger('right');
  61. return;
  62. }
  63.  
  64. document.documentElement.scrollTop += window.innerHeight - lineHeight * 2;
  65.  
  66. const chapterRect = chapter.getBoundingClientRect();
  67. if (
  68. chapterRect.top + chapterRect.height - window.innerHeight + lineHeight * 2 < 0 ||
  69. document.documentElement.scrollTop + window.innerHeight === document.documentElement.scrollHeight
  70. ) {
  71. endChapter = true;
  72. }
  73. });