Add-js/css

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

Verze ze dne 11. 09. 2019. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Add-js/css
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  给浏览器添加手动引入外部js及css的两个方法,方便临时引入外部文件调试页面
// @author       Sean
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 加载js
    function addjs(src) {
        var head = document.querySelector('head');
        var script = document.createElement('script');
        script.src = src+'';
        script.type = 'text/javascript';
        head.appendChild(script);
        return '外部js注入成功' + script.src;
    }
    // 加载css
    function addcss(href) {
        var head = document.querySelector('head');
        var link = document.createElement('link');
        link.href = href+'';
        link.rel = 'stylesheet';
        link.type = 'text/css';
        head.appendChild(link)
        return '外部css注入成功' + link.href;
    }
    // 注入浏览器window对象
    window.addjs = addjs;
    window.addcss = addcss;
})();