Source Viewer

View Page Source of any Website.

当前为 2020-10-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @version 6.7.2.1
  3. // @name Source Viewer
  4. // @name:de Seitenquelltext anzeiger
  5. // @description View Page Source of any Website.
  6. // @description:de Schauen Sie sich den Seitenquelltext von jeder beliebigen Website an.
  7. // @author wack.3gp
  8. // @copyright 2019+ , wack.3gp (https://greasyfork.org/users/4792)
  9. // @grant unsafeWindow
  10. // @grant GM_registerMenuCommand
  11. // @noframes
  12. // @include *
  13. // @license CC BY-NC-ND 4.0; http://creativecommons.org/licenses/by-nc-nd/4.0/
  14. // @namespace https://greasyfork.org/users/4792
  15. // @supportURL https://greasyfork.org/scripts/4611/feedback
  16. // @compatible Chrome tested with Tampermonkey
  17. // ==/UserScript==
  18.  
  19. if (document.cookie.indexOf(GM_info.script.name + '=hide') >= 0) {
  20. console.info('Cookie is set for ' + GM_info.script.name);
  21. GM_registerMenuCommand("Show view-source Button", function () {
  22. document.cookie = GM_info.script.name + '=hide; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;';
  23. console.info('Cookie for ' + GM_info.script.name + ' deleted!');
  24. location.reload();
  25. });
  26. viewsourcediv.style.display = "none";
  27. }
  28. else {
  29. GM_registerMenuCommand("Hide view-source Button", function () {
  30. var cookie = new Date();
  31. cookie = new Date(cookie.getTime() + 1000 * 60 * 60 * 24 * 365);
  32. document.cookie = GM_info.script.name + '=hide; path=/; expires=' + cookie.toGMTString() + ';';
  33. console.info('Set cookie for ' + GM_info.script.name);
  34. viewsourcediv.style.display = "none";
  35. });
  36. }
  37.  
  38. unsafeWindow.viewsource = function () {
  39. var source = "<html>";
  40. source += document.getElementsByTagName('html')[0].innerHTML;
  41. source += "</html>";
  42. source = source.replace(/</g, "&lt;").replace(/>/g, "&gt;");
  43. source = "<pre>" + source + "</pre>";
  44. var sourceWindow = window.open();
  45. sourceWindow.document.write(source);
  46. sourceWindow.document.close();
  47. if (window.focus) sourceWindow.focus();
  48. };
  49. // ==============
  50.  
  51. var body = document.body;
  52. if (body !== null) {
  53. var viewsourcediv = document.createElement("div");
  54. viewsourcediv.setAttribute('id', 'viewsource');
  55. viewsourcediv.innerHTML = "<center><button onclick='javascript:viewsource()'>Click to view source!</button></center>";
  56. body.appendChild(viewsourcediv);
  57. document.getElementById("viewsource").style = "position: fixed;right: 0;left: 0;bottom: 0px;margin: auto;";
  58. }
  59. // ==============