<commit_before>// ==UserScript==
// @name        CSS-fixer
// @namespace   http://www.hallvord.com
// @description Scans for and fixes -webkit-prefixed CSS
// @include     http://*
// @include     https://*
// @version     1
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_log
// @require    http://hallvord.com/temp/moz/css-browserside.js
// @run-at document-end
// ==/UserScript==

var fixedElms=[];
var warnAgainstPotentiallyOverwrittenValues = false;
// CSS property list, thanks to <NAME>. Extracted from http://meiert.com/en/indices/css-properties/ with this JS:
// var props = []; for(var elms = document.querySelectorAll('a code'),el,i=0; el=elms[i]; i++){props.push(el.textContent)}; JSON.stringify(props)
var allW3CSSProperties = ["align-content","align-items","align-self","alignment-adjust","alignment-baseline","all","anchor-point","animation","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-timing-function","appearance","azimuth","backface-visibility","background","background-attachment","background-clip","background-color","background-image","background-origin","background-position","background-repeat","background-size","baseline-shift","binding","bleed","bookmark-label","bookmark-level","bookmark-state","bookmark-target","border","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-decoration-break","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","chains","clear","clip","clip-path","clip-rule","color","color-interpolation-filters","color-profile","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","content","counter-increment","counter-reset","crop","cue","cue-after","cue-before","cursor","direction","display","dominant-baseline","drop-initial-after-adjust","drop-initial-after-align","drop-initial-before-adjust","drop-initial-before-align","drop-initial-size","drop-initial-value","elevation","empty-cells","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","float-offset","flood-color","flood-opacity","flow-from","flow-into","font","font-family","font-feature-settings","font-kerning","font-language-override","font-size","font-size-adjust","font-stretch","font-style","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-ligatures","font-variant-numeric","font-variant-position","font-weight","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-position","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphens","icon","image-orientation","image-resolution","ime-mode","inline-box-align","justify-content","justify-items","justify-self","left","letter-spacing","lighting-color","line-break","line-height","line-stacking","line-stacking-ruby","line-stacking-shift","line-stacking-strategy","list-style","list-style-image","list-style-position","list-style-type","margin","margin-bottom","margin-left","margin-right","margin-top","marker-offset","marks","mask","mask-box","mask-box-outset","mask-box-repeat","mask-box-slice","mask-box-source","mask-box-width","mask-clip","mask-image","mask-origin","mask-position","mask-repeat","mask-size","mask-source-type","mask-type","max-height","max-lines","max-width","min-height","min-width","move-to","nav-down","nav-index","nav-left","nav-right","nav-up","object-fit","object-position","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-wrap","overflow-x","overflow-y","padding","padding-bottom","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","page-policy","pause","pause-after","pause-before","perspective","perspective-origin","pitch","pitch-range","play-during","position","presentation-level","quotes","region-fragment","rendering-intent","resize","rest","rest-after","rest-before","richness","right","rotation","rotation-point","ruby-align","ruby-overhang","ruby-position","ruby-span","shape-image-threshold","shape-outside","shape-margin","size","speak","speak-as","speak-header","speak-numeral","speak-punctuation","speech-rate","stress","string-set","tab-size","table-layout","target","target-name","target-new","target-position","text-align","text-align-last","text-combine-horizontal","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-style","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-height","text-indent","text-justify","text-orientation","text-outline","text-overflow","text-shadow","text-space-collapse","text-transform","text-underline-position","text-wrap","top","transform","transform-origin","transform-style","transition","transition-delay","transition-duration","transition-property","transition-timing-function","unicode-bidi","vertical-align","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","volume","white-space","widows","width","word-break","word-spacing","word-wrap","wrap-flow","wrap-through","writing-mode","z-index"];

function doTheBigStyleFixing(){    
    //GM_log('GM CSS fixed running '+document.styleSheets.length);

    for(var el, i = document.styleSheets.length - 1; i>=0; i--){
        el = document.styleSheets[i];
        var fixupStyle = {"type": "stylesheet", stylesheet: {rules: []}};
        if(fixedElms.indexOf(el.ownerNode)>-1)continue;
        if(/style/i.test(el.ownerNode.tagName)){
            var rules = createFixupRulesFromCSS(stripHTMLComments(el.ownerNode.textContent));
            copyJSDefinedStyles(rules, fixupStyle);
            //fixupStyle.stylesheet.rules = fixupStyle.stylesheet.rules.concat(rules);
            var cssStr = css.stringify(fixupStyle);
            if(cssStr !== ''){
                GM_log('will insert: \n'+css.stringify(fixupStyle));
                GM_addStyle(cssStr);
            }
            fixedElms.push(document.styleSheets[document.styleSheets.length - 1]); // GM_addStyle inserts a <style> element, which doesn't need fixing later on..
        }else if(el.ownerNode.href){
            GM_xmlhttpRequest({method:'GET',url:el.ownerNode.href, onload:function(response){
                var fixupStyle = {"type": "stylesheet", stylesheet: {rules: []}};
                var rules = createFixupRulesFromCSS(response.responseText);
                copyJSDefinedStyles(rules, fixupStyle);
                var cssStr = css.stringify(fixupStyle);
                if(cssStr !== ''){
                    GM_log('will insert: \n'+css.stringify(fixupStyle));
                    GM_addStyle(cssStr);
                }
                fixedElms.push(document.styleSheets[document.styleSheets.length - 1]); // GM_addStyle inserts a <style> element, which doesn't need fixing later on..
            }, headers:{'Accept':'text/css'}});
        }else{
           GM_log('hm.. '+ el);
        }
        fixedElms.push(el.ownerNode);
    }
}

window.addEventListener('DOMContentLoaded', doTheBigStyleFixing, false);
window.addEventListener('load', doTheBigStyleFixing, false);

function createFixupRulesFromCSS(str){
    try{
        var obj = css.parse(stripHTMLComments(str));
    }catch(e){
        GM_log('failed to parse '+str);
        return [];
    }
    var fixupRules = [], fixupDeclarations, prop, value;
    for(var rule, i = 0; rule = obj.stylesheet.rules[i]; i++){
        insertFixupDeclarations(rule);<commit_msg>Bugfix: ignored next style sheet in document if we had no fixup style to insert<commit_after>// ==UserScript==
// @name        CSS-fixer
// @namespace   http://www.hallvord.com
// @description Scans for and fixes -webkit-prefixed CSS
// @include     http://*
// @include     https://*
// @version     1
// @grant       GM_xmlhttpRequest
// @grant       GM_addStyle
// @grant       GM_log
// @require    http://hallvord.com/temp/moz/css-browserside.js
// @run-at document-end
// ==/UserScript==

var fixedElms=[];
var warnAgainstPotentiallyOverwrittenValues = false;
// CSS property list, thanks to <NAME>. Extracted from http://meiert.com/en/indices/css-properties/ with this JS:
// var props = []; for(var elms = document.querySelectorAll('a code'),el,i=0; el=elms[i]; i++){props.push(el.textContent)}; JSON.stringify(props)
var allW3CSSProperties = ["align-content","align-items","align-self","alignment-adjust","alignment-baseline","all","anchor-point","animation","animation-delay","animation-direction","animation-duration","animation-fill-mode","animation-iteration-count","animation-name","animation-play-state","animation-timing-function","appearance","azimuth","backface-visibility","background","background-attachment","background-clip","background-color","background-image","background-origin","background-position","background-repeat","background-size","baseline-shift","binding","bleed","bookmark-label","bookmark-level","bookmark-state","bookmark-target","border","border-bottom","border-bottom-color","border-bottom-left-radius","border-bottom-right-radius","border-bottom-style","border-bottom-width","border-collapse","border-color","border-image","border-image-outset","border-image-repeat","border-image-slice","border-image-source","border-image-width","border-left","border-left-color","border-left-style","border-left-width","border-radius","border-right","border-right-color","border-right-style","border-right-width","border-spacing","border-style","border-top","border-top-color","border-top-left-radius","border-top-right-radius","border-top-style","border-top-width","border-width","bottom","box-decoration-break","box-shadow","box-sizing","break-after","break-before","break-inside","caption-side","chains","clear","clip","clip-path","clip-rule","color","color-interpolation-filters","color-profile","column-count","column-fill","column-gap","column-rule","column-rule-color","column-rule-style","column-rule-width","column-span","column-width","columns","contain","content","counter-increment","counter-reset","crop","cue","cue-after","cue-before","cursor","direction","display","dominant-baseline","drop-initial-after-adjust","drop-initial-after-align","drop-initial-before-adjust","drop-initial-before-align","drop-initial-size","drop-initial-value","elevation","empty-cells","filter","flex","flex-basis","flex-direction","flex-flow","flex-grow","flex-shrink","flex-wrap","float","float-offset","flood-color","flood-opacity","flow-from","flow-into","font","font-family","font-feature-settings","font-kerning","font-language-override","font-size","font-size-adjust","font-stretch","font-style","font-synthesis","font-variant","font-variant-alternates","font-variant-caps","font-variant-east-asian","font-variant-ligatures","font-variant-numeric","font-variant-position","font-weight","grid","grid-area","grid-auto-columns","grid-auto-flow","grid-auto-position","grid-auto-rows","grid-column","grid-column-end","grid-column-start","grid-row","grid-row-end","grid-row-start","grid-template","grid-template-areas","grid-template-columns","grid-template-rows","hanging-punctuation","height","hyphens","icon","image-orientation","image-resolution","ime-mode","inline-box-align","justify-content","justify-items","justify-self","left","letter-spacing","lighting-color","line-break","line-height","line-stacking","line-stacking-ruby","line-stacking-shift","line-stacking-strategy","list-style","list-style-image","list-style-position","list-style-type","margin","margin-bottom","margin-left","margin-right","margin-top","marker-offset","marks","mask","mask-box","mask-box-outset","mask-box-repeat","mask-box-slice","mask-box-source","mask-box-width","mask-clip","mask-image","mask-origin","mask-position","mask-repeat","mask-size","mask-source-type","mask-type","max-height","max-lines","max-width","min-height","min-width","move-to","nav-down","nav-index","nav-left","nav-right","nav-up","object-fit","object-position","opacity","order","orphans","outline","outline-color","outline-offset","outline-style","outline-width","overflow","overflow-wrap","overflow-x","overflow-y","padding","padding-bottom","padding-left","padding-right","padding-top","page","page-break-after","page-break-before","page-break-inside","page-policy","pause","pause-after","pause-before","perspective","perspective-origin","pitch","pitch-range","play-during","position","presentation-level","quotes","region-fragment","rendering-intent","resize","rest","rest-after","rest-before","richness","right","rotation","rotation-point","ruby-align","ruby-overhang","ruby-position","ruby-span","shape-image-threshold","shape-outside","shape-margin","size","speak","speak-as","speak-header","speak-numeral","speak-punctuation","speech-rate","stress","string-set","tab-size","table-layout","target","target-name","target-new","target-position","text-align","text-align-last","text-combine-horizontal","text-decoration","text-decoration-color","text-decoration-line","text-decoration-skip","text-decoration-style","text-emphasis","text-emphasis-color","text-emphasis-position","text-emphasis-style","text-height","text-indent","text-justify","text-orientation","text-outline","text-overflow","text-shadow","text-space-collapse","text-transform","text-underline-position","text-wrap","top","transform","transform-origin","transform-style","transition","transition-delay","transition-duration","transition-property","transition-timing-function","unicode-bidi","vertical-align","visibility","voice-balance","voice-duration","voice-family","voice-pitch","voice-range","voice-rate","voice-stress","voice-volume","volume","white-space","widows","width","word-break","word-spacing","word-wrap","wrap-flow","wrap-through","writing-mode","z-index"];

function doTheBigStyleFixing(){    
    //GM_log('GM CSS fixed running '+document.styleSheets.length);

    for(var el, i = document.styleSheets.length - 1; i>=0; i--){
        el = document.styleSheets[i];
        var fixupStyle = {"type": "stylesheet", stylesheet: {rules: []}};
        if(fixedElms.indexOf(el.ownerNode)>-1)continue;
        if(/style/i.test(el.ownerNode.tagName)){
            var rules = createFixupRulesFromCSS(stripHTMLComments(el.ownerNode.textContent));
            copyJSDefinedStyles(rules, fixupStyle);
            //fixupStyle.stylesheet.rules = fixupStyle.stylesheet.rules.concat(rules);
            var cssStr = css.stringify(fixupStyle);
            if(cssStr !== ''){
                GM_log('will insert: \n'+css.stringify(fixupStyle));
                GM_addStyle(cssStr);
                fixedElms.push(document.styleSheets[document.styleSheets.length - 1]); // GM_addStyle inserts a <style> element, which doesn't need fixing later on..
            }
        }else if(el.ownerNode.href){
            GM_xmlhttpRequest({method:'GET',url:el.ownerNode.href, onload:function(response){
                var fixupStyle = {"type": "stylesheet", stylesheet: {rules: []}};
                var rules = createFixupRulesFromCSS(response.responseText);
                copyJSDefinedStyles(rules, fixupStyle);
                var cssStr = css.stringify(fixupStyle);
                if(cssStr !== ''){
                    GM_log('will insert: \n'+css.stringify(fixupStyle));
                    GM_addStyle(cssStr);
                    fixedElms.push(document.styleSheets[document.styleSheets.length - 1]); // GM_addStyle inserts a <style> element, which doesn't need fixing later on..
                }
            }, headers:{'Accept':'text/css'}});
        }else{
           GM_log('hm.. '+ el);
        }
        fixedElms.push(el.ownerNode);
    }
}

window.addEventListener('DOMContentLoaded', doTheBigStyleFixing, false);
window.addEventListener('load', doTheBigStyleFixing, false);

function createFixupRulesFromCSS(str){
    try{
        var obj = css.parse(stripHTMLComments(str));
    }catch(e){
        GM_log('failed to parse '+str);
        return [];
    }
    var fixupRules = [], fixupDeclarations, prop, value;
    for(var rule, i = 0; rule = obj.stylesheet.rules[i]; i++){
        insertFixupDeclarations(rule);
{'fraction_non_alphanumeric': 0.21670177902621723, 'fraction_numerical': 0.001053370786516854, 'mean_word_length': 5.938286642306131, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3486343', 'n_tokens_mistral': 5048, 'n_tokens_neox': 4877, 'n_words': 379}