篡改猴|油猴脚本JavaScript常用脚本
以下是常用的脚本,在此备份
bing和google搜索页面宽度限制
// ==UserScript==
// @name 搜索页面宽度限制
// @namespace http://tampermonkey.net/
// @version 0.1
// @description 在Bing网站上应用自定义CSS
// @author You
// @match https://*.bing.com/search*
// @match https://*.google.com/search*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// 添加自定义CSS
GM_addStyle(`
body {
max-width: 1280px !important;
margin: 0 auto !important;
}
`);
})();
知乎与维基百科公式复制
(需要禁用解锁复制限制的插件才能正常使用)
// ==UserScript==
// @name FormulaCopier
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Copy LaTeX formulas when copying text on Zhihu and Wikipedia.
// @author Yuhang Chen(github.com/yuhangchen0)
// @match https://www.zhihu.com/*
// @match https://zhuanlan.zhihu.com/p/*
// @match https://*.wikipedia.org/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
document.addEventListener('copy', function(event) {
let selectedHtml = getSelectionHtml();
if (window.location.hostname.includes('zhihu.com')) {
handleZhihu(selectedHtml, event);
} else if (window.location.hostname.includes('wikipedia.org')) {
handleWiki(selectedHtml, event);
}
});
document.addEventListener('selectionchange', function() {
const allFormulas = document.querySelectorAll('.ztext-math');
allFormulas.forEach(formula => removeHighlightStyle(formula));
const sel = window.getSelection();
if (sel.rangeCount) {
for (let i = 0; i < sel.rangeCount; i++) {
const range = sel.getRangeAt(i);
const selectedFormulas = range.cloneContents().querySelectorAll('.ztext-math');
selectedFormulas.forEach(selectedFormula => {
allFormulas.forEach(pageFormula => {
if (selectedFormula.getAttribute('data-tex') === pageFormula.getAttribute('data-tex')) {
applyHighlightStyle(pageFormula);
}
});
});
}
}
});
function handleZhihu(selectedHtml, event) {
if (selectedHtml.includes('data-tex')) {
const container = document.createElement('div');
container.innerHTML = selectedHtml;
replaceZhihuFormulas(container, '.ztext-math', 'data-tex');
setClipboardData(event, container.textContent);
}
}
function handleWiki(selectedHtml, event) {
if (selectedHtml.includes('mwe-math-element')) {
const container = document.createElement('div');
container.innerHTML = selectedHtml;
replaceWikipediaFormulas(container);
setClipboardData(event, container.textContent);
}
}
function applyHighlightStyle(formula) {
const mathJaxSVG = formula.querySelector('.MathJax_SVG');
if (mathJaxSVG) {
mathJaxSVG.style.backgroundColor = 'lightblue';
}
}
function removeHighlightStyle(formula) {
const mathJaxSVG = formula.querySelector('.MathJax_SVG');
if (mathJaxSVG && mathJaxSVG.style) {
mathJaxSVG.style.backgroundColor = '';
}
}
function replaceWikipediaFormulas(container) {
const formulas = container.querySelectorAll('.mwe-math-element');
formulas.forEach(formula => {
const annotation = formula.querySelector('annotation[encoding="application/x-tex"]');
if (annotation) {
const texCode = annotation.textContent;
const texNode = document.createTextNode('$' + texCode + '$');
formula.replaceWith(texNode);
}
});
}
function replaceZhihuFormulas(container, selector, attribute) {
const formulas = container.querySelectorAll(selector);
formulas.forEach(formula => {
const texCode = formula.getAttribute(attribute);
const texNode = document.createTextNode('$' + texCode + '$');
formula.replaceWith(texNode);
});
}
function setClipboardData(event, text) {
event.clipboardData.setData('text/plain', text);
event.preventDefault();
}
function convertLineBreaks(node) {
if (node.nodeName === 'BR') {
node.parentNode.replaceChild(document.createTextNode('\n'), node);
} else if (node.nodeName === 'P' && node.nextElementSibling) {
// Add a newline after the section
node.appendChild(document.createTextNode('\n\n'));
} else {
const children = Array.from(node.childNodes);
for (let child of children) {
convertLineBreaks(child);
}
}
}
function getSelectionHtml() {
const sel = window.getSelection();
if (sel.rangeCount) {
const container = document.createElement('div');
for (let i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}
// Keep newline
convertLineBreaks(container);
return container.innerHTML;
}
return '';
}
})();
CSDN美化插件
// ==UserScript==
// @name CSDN优雅美化脚本-免登陆+旧版两栏+屏宽自动适配+自动展开+去广告
// @name:zh-CN CSDN优雅美化脚本-免登陆+旧版两栏+屏宽自动适配+自动展开+去广告
// @description 还你一个经典版的CSDN:作者信息和顶部导航栏保留,去掉右边评论区;内容自动展开;去广告;屏宽自动适配;净化剪贴板。
// @description:zh-TW 還你一個經典版的CSDN:作者信息和頂部導航欄保留,去掉右側評論區;內容自動展開;去廣告;屏寬自動適配;淨化剪貼板。
// @description:zh-HK 還你一個經典版的CSDN:作者信息和頂部導航欄保留,去掉右側評論區;內容自動展開;去廣告;屏寬自動適配;淨化剪貼板。
// @description:zh-CN 还你一个经典版的CSDN:作者信息和顶部导航栏保留,去掉右边评论区;内容自动展开;去广告;屏宽自动适配;净化剪贴板。
// @namespace https://github.com/z1064244797/CSDN-Beautify
// @version 2.9.7
// @author Nyaasu
// @match http*://blog.csdn.net/*/article/details/*
// @match http*://csdnnews.blog.csdn.net/article/details/*
// @run-at document-end
// @grant none
// @license CC-BY-NC-3.0
// @supportURL https://github.com/z1064244797/CSDN-Beautify/issues
// @date 08/11/2022
// ==/UserScript==
(function () {
'use strict';
// CSS (用魔法来打败魔法)
const style = document.createElement('style');
style.innerHTML = `
.passport-login-container {
display: none;
}
#groupfile {
max-height: 80%;
}
#footerRightAds {
display: none;
}
main {
float: none;
margin: 0 auto;
}
#passportbox {
display: none;
}
.login-mark {
display: none;
}
.toolbar-btn-vip {
display: none;
}
.csdn-common-logo-advert {
display: none;
}
.icon-fire {
display: none !important;
}
#toolbar-search-input {
text-indent: 16px !important;
}
body {
min-width: 0;
}
img[src="https://img-home.csdnimg.cn/images/20220805045438.png"] {
display: none;
}
.icon-mp-menu {
display: none;
}
#recommendNps {
display: none !important;
}
`;
document.head.appendChild(style);
resize();
//未登录复制代码限制
$('code').css({'user-select':'unset'})
$('#content_views pre').css({'user-select':'unset'})
//阅读全文
$('.hide-article-box').remove();
$('#article_content').css({
'height': 'initial'
});
//vip免广告 按钮
// $('.meau-gotop-box').remove();
//未登录提示
// $('.unlogin-box').remove();
//去除剪切板劫持
csdn.copyright.init("", "", "");
//移除左侧最新评论
// $('#asideNewComments').remove();
//移除左侧CSDN联系方式
// $('.persion_article').remove();
//移除右侧工具栏
// $('.tool-box').remove()
//下部推荐
// $('.recommend-box').remove();
//两栏处理
$('.blog_container_aside').remove();
// $('.nodata .container').css({'width':'1318px !important'})
// $('.nodata .tool-box .meau-list .btn-like-box p').css({'display': 'block'})
// $('.recommend-right').css({'display':'none'})
// $('.container').css({'width':'1318px'})
// $('.container main').css({'width': '1010px'})
// $('.container main .recommend-box .type_blog .content .desc').css({'width': '81%'})
// $('.container main .recommend-box .type_blog .content .blog_title_box').css({'width': '18%'})
// $("#mainBox > main").css("float","left"); //感谢 ID:potoo 的反馈
// $("aside").css("float","right");
// $("aside").css("padding-left","10px");
// $('body').css({'min-width':'0'});
// $('.csdn-toolbar').css({'min-width':'0'});
//去广告
// $('.pulllog-box').remove();
// $('.fourth_column').remove();
// $('.mb8').remove();
// $('newsfeed').remove();
// $('#asideFooter').remove();
$("li:contains('VIP会员')").remove();
$("#health-companies").remove();
// $('.light-box').remove();
// $("a[data-type='vip']").remove();
// $(".csdn-side-toolbar").remove();
// $(".vip-caise").remove();
// $('.csdn-tracking-statistics').remove();
$('#addAdBox').remove();
$('#recommendAdBox').remove();
setTimeout(() => {
$('[data-title="登录后复制"]').remove();
resize();
}, 800)
// 屏宽适配
function resize() {
var result1 = window.matchMedia('(min-width:1220px)');
var result2 = window.matchMedia('(min-width:1020px)');
if (result1.matches) {
console.log("大屏宽,恢复原样式");
$("aside").css({
'display': 'block'
});
$("main").css({
"width": "1110px",
});
$('.container').css({
'width': '1418px'
})
$(".main_father").css({
"width": "100%",
"cssText": "justify-content: center !important",
});
$("#mainBox").css("margin-left", "8px");
$("#csdn-toolbar").css("display", "block");
} else if (result2.matches) {
console.log("中屏宽,减小mainBox宽度");
$("aside").css({
'display': 'block'
});
$('.container').css({
'width': '1008px'
})
$("main").css({
"width": "970px",
});
$(".main_father").css({
"width": "1070px",
"cssText": "justify-content: center !important",
});
$("#mainBox").css("margin-left", "8px");
$("#csdn-toolbar").css("display", "block");
} else {
console.log("小屏宽,隐藏右侧信息栏,mainBox居中");
$("aside").css({
'display': 'none'
});
$('.container').css({
'width': '820px'
});
$("main").css({
"width": "800px",
});
$(".main_father").css({
"width": "1010px",
"cssText": "justify-content: left !important",
"padding-left": "0",
});
$(".btns").css("float", "right");
$(".csdn-toolbar > div").css("width", "870px");
$("#mainBox").css("margin-left", "0");
$("#csdn-toolbar").css("display", "none");
}
}
window.addEventListener('resize', function () {
resize();
});
// //显示评论区
// $('.comment-list-box').css({'display':'block'});
// $('.comment-list-box').css({'max-height':'870px'});
})();
