Samlib Reader

Делает самиздатовские текста более читабельными: смена фона на тёмный, смена шрифта на verdana, смена цвета текста на светлый, текст выровнен по ширине строки, добавлен автоматический перенос слов

当前为 2021-01-11 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Samlib Reader
  3. // @description Делает самиздатовские текста более читабельными: смена фона на тёмный, смена шрифта на verdana, смена цвета текста на светлый, текст выровнен по ширине строки, добавлен автоматический перенос слов
  4. // @copyright 2019, Angens (https://openuserjs.org/users/angens)
  5. // @license MIT
  6. // @version 2.0.3
  7. // @match http://samlib.ru/*/*/*.shtml
  8. // @exclude http://samlib.ru/*/*/index*.shtml
  9. // @exclude http://samlib.ru/*/*/stat.shtml
  10. // @grant none
  11. // @namespace https://greasyfork.org/users/386214
  12. // ==/UserScript==
  13. //
  14. // ==OpenUserJS==
  15. // @author angens
  16. // ==/OpenUserJS==
  17.  
  18.  
  19.  
  20. function changer(){
  21.  
  22. document.querySelector("body").setAttribute("lang", "ru");
  23. document.querySelector("body").setAttribute("style", "-moz-hyphens: auto; -webkit-hyphens: auto; -ms-hyphens: auto; white-space: unset;");
  24.  
  25. let treeWalker = document.createTreeWalker(document.body, NodeFilter.SHOW_ALL, null, false);
  26. let description = document.createElement('div');
  27. description.id = "SamLibReaderDescription";
  28. let commnts = [];
  29. // Блок работы с комментариями
  30. //Ищем последний комментарий
  31. while (treeWalker.nextNode()){
  32. if (treeWalker.currentNode.nodeType === 8)
  33. commnts.push(treeWalker.currentNode);
  34. if (commnts.length == 16) //Когда нужный комментарий найден, собираем дочерние элементы(это должно быть описание)
  35. //desc_nodes.push(treeWalker.currentNode);
  36. while(treeWalker.currentNode.nextSibling){
  37. description.append(treeWalker.currentNode.nextSibling);
  38. }
  39. }
  40. // Блок работы с произведением
  41. let nodes = document.querySelectorAll("dd, p");
  42.  
  43. let new_element = document.createElement('div');
  44.  
  45. new_element.id = "SamLibReader";
  46. new_element.style.color = "wheat";
  47. new_element.style.fontSize = "18px";
  48. new_element.style.fontFamily = "verdana";
  49. new_element.style.backgroundColor = "#212127";
  50. new_element.style.paddingTop = "5%";
  51. new_element.style.paddingLeft = "5%";
  52. new_element.style.paddingRight = "5%";
  53. new_element.style.marginLeft = "25%";
  54. new_element.style.marginRight = "25%";
  55. new_element.style.textAlign = "justify";
  56. if(nodes[0])
  57. nodes[0].parentElement.insertBefore(new_element, nodes[0]);
  58.  
  59. for (let i = 0; i < nodes.length; i++){
  60. new_element.append(nodes[i]);
  61. }
  62. document.body.append(description);
  63. }
  64.  
  65.  
  66. document.addEventListener("DOMContentLoaded", changer());