1/* 2 * Remove Uppercase Accents for Wordpress 3 */ 4(function () { 5 'use strict'; 6 7 window.addEventListener('DOMContentLoaded', function () { 8 removeUppercaseAccents(); 9 }); 10 11 ajaxLoaded(removeUppercaseAccents); 12 13 // Remove the uppercase accents. 14 function removeUppercaseAccents() { 15 const accents = rua.accents; 16 for (const entry of getSelectorsList()) { 17 let text = (entry.tagName && entry.tagName.toLowerCase() === 'input') ? entry.value : entry.innerHTML; 18 accents.forEach(function (item) { 19 const reg = new RegExp(item.original, 'g'); 20 text = text.replace(reg, item.convert); 21 }); 22 entry.innerHTML = text; 23 } 24 } 25 26 // Get the selectors' list. 27 function getSelectorsList() { 28 const cssProp = 'text-transform'; 29 const cssValue = 'uppercase'; 30 const manuallySetSelectors = rua.selectors; 31 const action = rua.selAction; 32 let selectors = findUppercaseSelectors(); 33 34 if ('exclude' === action && false === manuallySetSelectors.isEmpty()) { 35 selectors = withoutExcludedSelectors(manuallySetSelectors); 36 } else if (false === manuallySetSelectors.isEmpty()) { 37 selectors = manuallySetSelectors; 38 } 39 40 const selectorsArr = document.querySelectorAll(selectors); 41 const l = selectorsArr.length; 42 43 let i, results = []; 44 for (i = 0; i < l; i++) { 45 // Test whether the element is really text-transform:uppercase; 46 if (window.getComputedStyle(selectorsArr[i], null).getPropertyValue(cssProp) === cssValue) { 47 results.push(selectorsArr[i]); 48 } 49 } 50 return results; 51 } 52 53 // Exclude specific selectors 54 function withoutExcludedSelectors(manuallySet) { 55 const excludesArr = manuallySet.split(','); 56 let withoutExcludes = findUppercaseSelectors().split(',').map(function (item) { 57 return item.trim(); 58 }); 59 for (const selector of excludesArr) { 60 const trimmed = selector.trim(); 61 if (withoutExcludes.includes(trimmed)) { 62 withoutExcludes = withoutExcludes.filter(function (e) { 63 return e !== trimmed; 64 }); 65 } 66 } 67 return withoutExcludes.join(','); 68 } 69 70 // Find all CSS selectors that use text-transform:uppercase. 71 function findUppercaseSelectors() { 72 const loc = new URL(window.location, location); 73 let variations = ['[style*="text-transform:uppercase"],[style*="text-transform: uppercase"]']; 74 const searchFor = /\btext-transform:\s*uppercase;/; 75 const styles = document.styleSheets; 76 let i, j, l, rules, rule; 77 78 for (i = 0; i < styles.length; i++) { 79 const url = new URL(styles[i].href, location); 80 if (url.origin === loc.origin) { 81 rules = styles[i].cssRules; 82 l = rules.length; 83 for (j = 0; j < l; j++) { 84 rule = rules[j]; 85 if (searchFor.test(rule.cssText)) { 86 variations.push(rule.selectorText); 87 } 88 } 89 } 90 } 91 let selectors = variations.filter(function (el) { // Clear empty and undefined. 92 return el != null; 93 }); 94 return selectors.join(','); 95 } 96 97 // Detect when all ajax calls are finished. 98 function ajaxLoaded(callback) { 99 const send = XMLHttpRequest.prototype.send 100 XMLHttpRequest.prototype.send = function () { 101 this.addEventListener('load', function () { 102 callback(); 103 }) 104 return send.apply(this, arguments); 105 } 106 } 107 108 // Test if a string is empty or contain only blank space. 109 String.prototype.isEmpty = function () { 110 return (this.length === 0 || !this.trim()); 111 }; 112})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.