ShowCssStyle

show css style

当前为 2019-10-11 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         ShowCssStyle
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  show css style
// @author       Roastwind
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
'use strict';
// 创意来源: https://juejin.im/pin/5d80b839e51d456cecc4a8e4
// 按钮id
var _id = 'show-css-style'
// style id
var _style_id = 'add-style'
var _outline_css = `html * { outline: 1px solid red }#${_id}{outline: none;}#${_id} * {outline: none;}`

var init = function() {
    // 容器
    var btnWrap = document.createElement('div')
    btnWrap.style.position = 'fixed'
    btnWrap.style.zIndex = '99999'
    btnWrap.style.width = '42px'
    // btnWrap.style.height = '60px'
    btnWrap.style.left = '0'
    btnWrap.style.top = '200px'
    btnWrap.style.display = 'flex'
    btnWrap.style.flexDirection = 'column'
    btnWrap.setAttribute('id', _id)

    // 展示按钮
    var showBtn = document.createElement('btn')
    showBtn.style.width = '40px'
    showBtn.style.height = '20px'
    showBtn.style.lineHeight = '20px'
    showBtn.style.border = '1px solid gray'
    showBtn.style.marginBottom = '10px'
    showBtn.style.borderRadius = '5px'
    showBtn.style.textAlign = 'center'
    showBtn.style.cursor = 'pointer'
    showBtn.innerText = 'show'
    showBtn.addEventListener('click', function() {
        addCssLine()
    })

    // 隐藏按钮
    var hideBtn = document.createElement('btn')
    hideBtn.style.width = '40px'
    hideBtn.style.height = '20px'
    hideBtn.style.lineHeight = '20px'
    hideBtn.style.border = '1px solid gray'
    hideBtn.style.marginBottom = '10px'
    hideBtn.style.borderRadius = '5px'
    hideBtn.style.textAlign = 'center'
    hideBtn.style.cursor = 'pointer'
    hideBtn.innerText = 'hide'
    hideBtn.addEventListener('click', function() {
        removeCssLine()
    })

    btnWrap.appendChild(showBtn)
    btnWrap.appendChild(hideBtn)
    document.body.appendChild(btnWrap)
}
var addCssLine = function() {
    var hasAddStyle = document.querySelector(`#${_style_id}`)
    if (hasAddStyle) { return }

    var style = document.createElement('style')
    style.textContent = _outline_css
    style.setAttribute('id', _style_id)
    document.body.appendChild(style)
}
var removeCssLine = function() {
    var addStyle = document.querySelector(`#${_style_id}`)
    if (addStyle) {
        addStyle.remove()
    }
}
init()
})();