Add-js/css

给浏览器添加手动引入外部js及css的两个方法,方便临时引入外部文件调试页面

As of 2019-09-11. See the latest version.

  1. // ==UserScript==
  2. // @name Add-js/css
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description 给浏览器添加手动引入外部js及css的两个方法,方便临时引入外部文件调试页面
  6. // @author Sean
  7. // @match *://*/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // 加载js
  15. function addjs(src) {
  16. var head = document.querySelector('head');
  17. var script = document.createElement('script');
  18. script.src = src+'';
  19. script.type = 'text/javascript';
  20. head.appendChild(script);
  21. return '外部js注入成功' + script.src;
  22. }
  23. // 加载css
  24. function addcss(href) {
  25. var head = document.querySelector('head');
  26. var link = document.createElement('link');
  27. link.href = href+'';
  28. link.rel = 'stylesheet';
  29. link.type = 'text/css';
  30. head.appendChild(link)
  31. return '外部css注入成功' + link.href;
  32. }
  33. // 注入浏览器window对象
  34. window.addjs = addjs;
  35. window.addcss = addcss;
  36. })();