Lobsters Favicons

Favicons for Lobsters

  1. // ==UserScript==
  2. // @name Lobsters Favicons
  3. // @namespace https://yfu.tw
  4. // @match https://lobste.rs/*
  5. // @grant GM.addElement
  6. // @version 1.0
  7. // @author yufu
  8. // @description Favicons for Lobsters
  9. // @license MIT
  10. // @icon https://icons.duckduckgo.com/ip3/lobste.rs.ico
  11. // ==/UserScript==
  12.  
  13. // patched by yufu
  14. // working with Autopage
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. let size = 12;
  20.  
  21.  
  22. function doOne(link) {
  23. if (link.hasAttribute('has-icon')) return;
  24. let domain;
  25. try {
  26. domain = new URL(link.href).hostname;
  27. } catch(err) {
  28. return;
  29. }
  30. link.setAttribute('has-icon', true);
  31. const imageUrl = `https://icons.duckduckgo.com/ip3/${domain}.ico`;
  32. const container = document.createElement('span');
  33. container.style.paddingRight = '0.25em';
  34. container.style.paddingLeft = '0.175em';
  35. link.prepend(container);
  36.  
  37. GM.addElement(container, 'img', {
  38. src: imageUrl,
  39. width: size,
  40. height: size
  41. });
  42. }
  43. function doit() {
  44. for (let link of document.querySelectorAll('a.u-url')) {
  45. doOne(link);
  46. }
  47. }
  48.  
  49. // dynamically loaded <a> tag for Autopage
  50. function aObserver() {
  51. const callback = (mutationsList, observer) => {
  52. for (const mutation of mutationsList) {
  53. for (const target of mutation.addedNodes) {
  54. if (target.nodeType != 1) return
  55. if (target.tagName === 'A') {
  56. doOne(target);
  57. } else {
  58. for (let link of document.querySelectorAll('a.u-url')) {
  59. doOne(link);
  60. }
  61. }
  62. }
  63. }
  64. };
  65.  
  66. const observer = new MutationObserver(callback);
  67. observer.observe(document, { childList: true, subtree: true });
  68. }
  69.  
  70. doit();
  71. aObserver();
  72.  
  73. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址