手机浏览器console控制台加载

能让手机浏览器的像电脑脑F12一样调试代码,查看console控制台信息,查看网页源码,js调试等。

  1. // ==UserScript==
  2. // @name 手机浏览器console控制台加载
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description 能让手机浏览器的像电脑脑F12一样调试代码,查看console控制台信息,查看网页源码,js调试等。
  6. // @description:en load the web page console to debug or get some information etc.
  7. // @author 夜雨
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @grant GM_registerMenuCommand
  11. // @license MIT
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. (function () {
  16. 'use strict';
  17.  
  18. const JSURL = 'https://s4.zstatic.net/ajax/libs/eruda/3.2.1/eruda.min.js'
  19. function loadScript(url, callback) {
  20. if(document.querySelector("#eruda")){
  21. callback();
  22. return
  23. }
  24. const script = document.createElement('script');
  25. script.setAttribute("id","eruda")
  26. script.type = 'text/javascript';
  27.  
  28. script.onload = function() {
  29. callback();
  30. };
  31.  
  32. script.src = url;
  33. document.head.appendChild(script);
  34. }
  35.  
  36. let show = false;
  37.  
  38. try {
  39. GM_registerMenuCommand("打开/关闭", function (event) {
  40. if(!show){
  41. loadScript(JSURL, () =>{
  42. eruda.init({
  43. useShadowDom:true,
  44. autoScale:true,
  45. defaults:{
  46. displaySize: 40,
  47. transparency: 0.9
  48. }
  49. });
  50. });
  51. }else {
  52. eruda && eruda.destroy();
  53. }
  54. show = !show;
  55. }, "openEruda");
  56. }catch (ex){
  57. loadScript(JSURL, () =>{
  58. eruda.init({
  59. useShadowDom:true,
  60. autoScale:true,
  61. defaults:{
  62. displaySize: 40,
  63. transparency: 0.9
  64. }
  65. });
  66. });
  67. }
  68.  
  69. })();