XKCD Title

Adds the very important title of the XKCD Strips below the picture.

当前为 2014-07-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name XKCD Title
  3. // @namespace http://jellefresen.nl/XKCD
  4. // @description Adds the very important title of the XKCD Strips below the picture.
  5. // @include http://xkcd.com/*
  6. // @include http://www.xkcd.com/*
  7. // @exclude http://xkcd.com/archive
  8. // @exclude http://www.xkcd.com/archive
  9. // @exclude http://xkcd.com/store
  10. // @exclude http://www.xkcd.com/store
  11. // @exclude http://xkcd.com/about
  12. // @exclude http://www.xkcd.com/about
  13. // @version 0.0.1.20140705065009
  14. // ==/UserScript==
  15.  
  16. var image = document.getElementById("middleContent").getElementsByTagName('img')[0];
  17.  
  18. // create a div that is invisible and becomes visible when the mouse hovers over it
  19. var title_text = document.createElement("div");
  20. title_text.setAttribute('style', 'margin: auto; width:70%; color:#ffffff; font-size:small; font-style:italic');
  21. title_text.setAttribute('onMouseOver','this.style.color=\'#000000\'');
  22. title_text.setAttribute('onMouseOut', 'this.style.color=\'#ffffff\'');
  23.  
  24. // apply a bold "Title: "
  25. var title_header = document.createElement("b");
  26. var title_header_content = document.createTextNode("Title: ");
  27. title_header.appendChild(title_header_content);
  28. title_text.appendChild(title_header);
  29.  
  30. // add the Title text
  31. var title_content = document.createTextNode(image.title);
  32. title_text.appendChild(title_content);
  33.  
  34. // Throw it after the big picture
  35. var root = image.parentNode;
  36. var next = image.nextSibling;
  37. root.insertBefore(document.createElement("br"), next);
  38. root.insertBefore(title_text, next);
  39. root.removeChild(next);
  40.  
  41. //.user.js