narrow img

缩小网页图片,上班摸鱼专用

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name               narrow img
// @name:zh-CN         缩小网页图片
// @namespace          daizp
// @version            0.2.0
// @description        缩小网页图片,上班摸鱼专用
// @description:zh-cn  缩小网页图片,上班摸鱼专用
// @author             daizp
// @include            *
// @grant              none
// ==/UserScript==

(function () {
    narrow_img();
    //页面加载完成缩小全部图片
    function narrow_img(){
        var pic = document.getElementsByTagName('img');
        for(var i=0;i<pic.length;i++){
            pic[i].setAttribute('style', 'max-height: 100px; max-width: 200px;');
            //添加鼠标经过事件
            pic[i].setAttribute("onmouseOver","big_img(this)");
            pic[i].setAttribute("onmouseOut","small_img(this)");
        }
    }
    //if(e.getAttribute("style") != null && e.getAttribute("style").indexOf("max-height") > -1) {
    //    e.removeAttribute("style");
    //}
var scriptText=`
//鼠标移入放大图片
function big_img(e){
    e.removeAttribute("style");
}
//鼠标移出缩小图片
function small_img(e){
    e.setAttribute('style', 'max-height: 100px; max-width: 200px;');
}
`;
    //感谢 https://cloud.tencent.com/developer/ask/217625 提供解决方法
    //使用此方法解决 Uncaught ReferenceError 错误
    var newScript = document.createElement("script");
    var inlineScript = document.createTextNode(scriptText);
    newScript.appendChild(inlineScript);
    document.body.appendChild(newScript);
})();