Greasy Fork is available in English.
2024/5/24 10:58:15
当前为
// ==UserScript==
// @name 东方财富新版本页面优化去广告
// @namespace Violentmonkey Scripts
// @match *://quote.eastmoney.com/concept/*
// @grant none
// @version 1.1
// @author -
// @grant GM_addStyle
// @license MIT
// @description 2024/5/24 10:58:15
// ==/UserScript==
(function () {
const classesToHide = [
'.hlinetg',
'.scatg',
'.emleftfloattg',
'.footertg',
'.footer2016',
'.feedback',
'.guid',
'.bp2sll',
'.bp2slr',
'#posteditor',
'.csiderbox:nth-of-type(1)',
'.csiderbox:nth-of-type(2)',
'.csiderbox:nth-of-type(5)',
'.csiderbox:nth-of-type(8)',
'.history',
'.zxg_t',
'.backtop',
'.zxght'
];
classesToHide.forEach(className => {
GM_addStyle(`${className} { display: none !important; }`);
});
GM_addStyle('#mainlist { max-height: 600px !important;overflow: hidden;overflow-y: auto;width: 1200px}');
GM_addStyle('.table_list {width: 1200px}')
GM_addStyle('.mock {z-index: 999999999999999999}')
GM_addStyle('.bp2sr {position: fixed;top: 26px; right: 12px; overflow-x: auto; height: 1000px;padding-bottom: 24px}');
GM_addStyle('::-webkit-scrollbar { display: none !important;}');
GM_addStyle('.mainbody { margin-left: 260px !important }');
GM_addStyle('.zxglist_ul { height: 800px !important;}');
document.body.style.overflow = 'hidden';
document.body.style.overflow = 'auto';
function reorderDivs() {
var parent = document.querySelector(".bp2sr");
var children = Array.from(parent.getElementsByClassName("csiderbox"));
children.reverse();
parent.innerHTML = '';
children.forEach(function (child) {
parent.appendChild(child);
});
}
window.addEventListener('load', reorderDivs);
function calcRange(expr) {
const pattern = /([\d\.]+)\s*([万千亿]?)/g;
const matches = [...expr.matchAll(pattern)];
if (matches.length !== 2) return "格式错误";
const unitMap = { "亿": 1e8, "万": 1e4, "千": 1e3, "": 1 };
const values = matches.map(m => parseFloat(m[1]) * unitMap[m[2] || ""]);
const units = matches.map(m => m[2] || "");
if (units[0] !== units[1]) return "单位不一致";
const diff = (values[0] - values[1]) / unitMap[units[0]];
return `${diff.toFixed(2)}${units[0]}`;
}
const priceContainer = document.querySelector(".csn_wbwc_mm2 table tbody");
if (priceContainer) {
const observer = new MutationObserver(() => {
const outerText = document.querySelector('.csn_wbwc_mm2 .price_up')?.innerText;
const innerText = document.querySelector('.csn_wbwc_mm2 .price_down')?.innerText;
if (!outerText || !innerText) return;
const diffText = `多空 = ${calcRange(`${outerText} - ${innerText}`)}`;
// 结果放到监听区域之外,防止死循环
let resultElem = document.querySelector(".calc-result");
if (!resultElem) {
resultElem = document.createElement("div");
resultElem.className = "calc-result";
resultElem.style.marginLeft = "10px";
resultElem.style.color = "blue";
resultElem.style.fontWeight = "bold";
priceContainer.parentElement.parentElement.appendChild(resultElem);
}
resultElem.textContent = diffText;
});
observer.observe(priceContainer, {
childList: true,
subtree: true,
characterData: true
});
}
})()