Replace Title Conlon

Replace Title Conlon in the web page

当前为 2023-11-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Replace Title Conlon
  3. // @namespace h
  4. // @version 1.1
  5. // @description Replace Title Conlon in the web page
  6. // @author amormaid
  7. // @include http*://*/*
  8. // @grant none
  9. // @run-at document-end
  10. // @license MIT License
  11. // ==/UserScript==
  12. (function() {
  13. 'use strict';
  14.  
  15. function is(target, type){
  16. return Object.prototype.toString.call(target).slice(8, -1).toLowerCase() === `${type}`.toLowerCase()
  17. }
  18.  
  19. function get_the_most_used_fontsize() {
  20. let nodes = document.querySelectorAll('*');
  21. let nodes_filtered = Array.from(nodes).filter(e => {
  22. let is_non_text = ['SCRIPT', 'STYLE', 'TEXTAREA'].includes(e.nodeName);
  23. let is_text = e.childNodes.length && is(e.childNodes[0], 'text');
  24. return !is_non_text && is_text
  25. });
  26.  
  27. let statistics = nodes_filtered.reduce((acc, cur) => {
  28. let fontSize = getComputedStyle(cur).fontSize
  29. acc[fontSize] = (acc[fontSize] || 0) + 1
  30. return acc
  31. },{})
  32. let the_most_used = Math.max(...Object.values(statistics))
  33. let the_most_used_fontsize = Object.keys(statistics).find(key => statistics[key] === the_most_used)
  34. return the_most_used_fontsize
  35. }
  36.  
  37. let content_fontsize = parseInt(get_the_most_used_fontsize())
  38.  
  39. let content_to_replaced = Array.from(document.querySelectorAll('*')).filter(e => !['SCRIPT', 'STYLE', 'TEXTAREA'].includes(e.nodeName) && e.childNodes.length && is(e.childNodes[0], 'text') && e.innerHTML && e.innerHTML.includes(':'))
  40.  
  41. content_to_replaced.forEach(e => {
  42. if(parseFloat(getComputedStyle(e).fontSize) > content_fontsize) {
  43. console.log('replcing ', e)
  44. e.innerHTML = e.innerHTML.replace(':', ' ')
  45. e.style.color = 'red'
  46. }
  47. })
  48. })();
  49.