Hide VScode Live Server

12/28/2021, 9:44:59 AM

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Hide VScode Live Server
// @namespace   Violentmonkey Scripts
// @match       http://127.0.0.1:550*/*
// @run-at      document-idle
// @grant       none
// @version     1.3
// @author      Mikhail 'UniBreakfast' Ninin
// @license     MIT 
// @description 12/28/2021, 9:44:59 AM
// ==/UserScript==

hideLiveServer()

function hideLiveServer() {
  const {body} = document
  const script = findScriptByText('LiveServer')
  const comment = findCommentByText('live-server')
  
  if (script) script.remove()
  if (comment) comment.remove()
  
  setTimeout(() => {
    body.classList.remove('vsc-initialized')
    if (!body.className) body.removeAttribute('class')
  }, 500)
}

function findCommentByText(text) {
  return Array.from(document.body.childNodes).find(node => node.textContent.includes('live-server'))
}

function findScriptByText(text) {
  return Array.from(document.scripts).find(script => script.textContent.includes(text))
}