Greasy Fork

Greasy Fork is available in English.

只看博客内容

包含【CSDN,简书,博客园,知乎,掘金,51CTO,阿里开发者社区,腾讯开发者社区,微信】

当前为 2022-08-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        只看博客内容
// @namespace    https://gitee.com/WHF-ZUCC/plugin
// @version     1.12
// @author       WhHF
// @license MIT
// @namespace   Violentmonkey Scripts
// @match       *://blog.csdn.net/*/article/details/*
// @match       *://www.jianshu.com/p/*
// @match       *://www.cnblogs.com/*/p/*
// @match       *://zhuanlan.zhihu.com/p/*
// @match       *://juejin.cn/post/*
// @match       *://blog.51cto.com/u_*
// @match       *://cloud.tencent.com/developer/article/*
// @match       *://developer.aliyun.com/article/*
// @match       *://mp.weixin.qq.com/*
// @match       *://www.it610.com/article/*
// @grant       none
// @author      -
// @description 包含【CSDN,简书,博客园,知乎,掘金,51CTO,阿里开发者社区,腾讯开发者社区,微信】
// ==/UserScript==



// 去掉 (xx条消息)
(function() {
    'use strict';
    window.onload = function() {
        let title = document.getElementsByTagName("title")[0];
        title.innerText = title.innerText.match(/(\([0-9]+.*(?=私信|消息).*?\)\s*)?(.+)/)[2];
    }
})();


// 调整dom元素
function dom_adjustment(dom){
  dom.style.width = '95%';
  dom.style.margin = 'auto'
  document.querySelector('body').style.background = '#FFFFFF';
  // dom.style.backgroundColor = '#FFFFFF';
  // dom.style.backgroundColor = '#f5f6f7';
  const children2 = dom.children
  for (var i = children2.length - 1; i >= 0; i--) {
    children2[i].style.width = '100%';
    children2[i].style.margin = '0';
    children2[i].style.padding = '0';
    children2[i].style.border = '0';
  }
  
}

function see(host){
  
  
  if(host=='blog.csdn.net'){
      // 关闭“CSDN:关注博主即可阅读全文”
      // 参考:https://www.isolves.com/it/cxkf/yy/js/2022-06-29/56707.html
      var article_content=document.getElementById("article_content");
      if(!article_content.hasAttribute('style')){
        return;
      }
      article_content.removeAttribute("style");

      var follow_text=document.getElementsByClassName('follow-text')[0];
      follow_text.parentElement.parentElement.removeChild(follow_text.parentElement);

      var  hide_article_box=document.getElementsByClassName(' hide-article-box')[0];
      hide_article_box.parentElement.removeChild(hide_article_box);
  }else if(host=='cloud.tencent.com'){
    var button=document.querySelector("#react-root > div:nth-child(1) > div.J-body.col-body.pg-2-article > div.com-3-layout > div.layout-main > section.com-2-panel.col-2-article.J-articlePanel > div.com-markdown-collpase.com-markdown-collpase-hide > div.com-markdown-collpase-toggle > a");
    if(button)button.click();
  }
  
}

function get_dom (host) {
    const map = {
      'blog.csdn.net':'#article_content',
      'www.jianshu.com':'div > div > div > div > section:nth-child(1)',
      'www.cnblogs.com':'div.post',
      'zhuanlan.zhihu.com':'#root > div > main > div > article',
      'juejin.cn':'#juejin > div.view-container > main > div > div.main-area.article-area > article',
      'blog.51cto.com':'#page_center > article > div.common-section.common-spacing.mb30.article-detail > div.article-content-wrap',
      'developer.aliyun.com':'body > div.article-detail > div.article-wrapper > div.left-content > div.content-wrapper',
      'cloud.tencent.com':'#react-root > div:nth-child(1) > div.J-body.col-body.pg-2-article > div.com-3-layout > div.layout-main > section.com-2-panel.col-2-article.J-articlePanel',
      'mp.weixin.qq.com':'#img-content',
      'www.it610.com':'body > div:nth-child(3) > div > div > div.col-md-9',
      };
  
    const selector = map[host];
    const dom = document.querySelector(selector);
    return dom;
}

// 只保留内容
function body_just_content (dom) {
    
    const body = document.body;
  
    // var dom2 = dom;
    // while(dom2.parentElement.tagName!='BODY'){
    //   dom2 = dom2.parentElement;
    // }
    // body.removeChild(dom2);
  
    const children = body.children
    for (var i = children.length - 1; i >= 0; i--) {
      if("LINK"!=children[i].tagName){
        body.removeChild(children[i]);
      }
    }
    
    body.appendChild(dom);
};


// 知乎图片懒加载,导致图片无法显示
function show_img () {
    attribute = 'data-actualsrc';
    imgs = document.querySelectorAll('img['+attribute+']');
    for (var i = imgs.length - 1; i >= 0; i--) {
      img = imgs[i];
      imgs[i].setAttribute('src',imgs[i].getAttribute(attribute));
    }
};

function main(host){
    'use strict';
    see(host);
  
    const dom = get_dom (host);
    body_just_content(dom);
    dom_adjustment(dom);
    show_img();
}


const host = window.location.host;
if(host in ['www.jianshu.com']){
  window.onload=function(){main(host);};
}else{
  main(host);
}