Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name avoid habit render bug
- // @description 本文途切れバグ回避のためフェードインCSS除去
- // @include http*://*
- function removeFadeinAnimation() {
- const rulesByAnimation = {};
- const fadeinAnimationsSet = new Set();
- const sheets = document.styleSheets;
- // console.log(sheets);
- function eachRules(rules) {
- Array.from(rules).forEach(rule => {
- const type = rule.type;
- if (type === CSSRule.STYLE_RULE) {
- const animationValue =
- rule.style.animationName || rule.style.animation;
- if (animationValue) {
- const animationName = animationValue
- .split(" ")
- .slice(-1)[0];
- // console.log(animationName, cssText, i, j);
- if (rulesByAnimation[animationName] === undefined)
- rulesByAnimation[animationName] = [];
- rulesByAnimation[animationName].push(rule);
- }
- } else if (type === CSSRule.KEYFRAMES_RULE) {
- // console.log(rule);
- const keyRules = rule.rules || rule.cssRules;
- const opacityKFs = Array.from(keyRules)
- .filter(
- rule =>
- rule.type === CSSRule.KEYFRAME_RULE &&
- rule.style.length === 1 &&
- rule.style[0] === "opacity"
- )
- .reduce((obj, rule) => {
- obj[rule.keyText] = rule.style.opacity;
- return obj;
- }, {});
- if (opacityKFs["0%"] === "0" && opacityKFs["100%"] === "1") {
- fadeinAnimationsSet.add(rule.name);
- }
- } else if (type === CSSRule.MEDIA_RULE) {
- const rules = rule.rules || rule.cssRules;
- // console.log(rules);
- eachRules(rules);
- }
- });
- }
- Array.from(sheets).forEach(sheet => {
- try {
- const rules = sheet.rules || sheet.cssRules;
- eachRules(rules);
- } catch (error) {
- console.log(error);
- }
- });
- const fadeinAnimations = Array.from(fadeinAnimationsSet.values());
- const fadeinRules = Object.keys(rulesByAnimation)
- .filter(a => fadeinAnimations.includes(a))
- .map(a => rulesByAnimation[a])
- .reduce((arr, val) => arr.concat(val), []);
- // console.log(fadeinRules, fadeinAnimations);
- // フェードインするアニメーションのCSSルールを除去
- fadeinRules.forEach(fadeinRule => {
- const rule = fadeinRule;
- // console.log(rule);
- rule.style.animation = "none";
- rule.style.animationName = "none";
- rule.style.cssText += "opacity: 1 !important;";
- });
- }
- window.addEventListener("load", removeFadeinAnimation);
- removeFadeinAnimation();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement