Skip to content

Instantly share code, notes, and snippets.

@w-log
Created March 29, 2018 09:03
Show Gist options
  • Save w-log/020b21acbb99c09d2cdb34abc7de0363 to your computer and use it in GitHub Desktop.
Save w-log/020b21acbb99c09d2cdb34abc7de0363 to your computer and use it in GitHub Desktop.
자주사용하는 유틸함수들
function getUrlParameterMap() {
var queryString = location.search.replace(/^[?]/, '');
var params = '{' + queryString.split('&').map(function (val) {
var valArr = val.split('=');
return '\"' + valArr[0] + '\" : \"' + (valArr[1] || '') + '\"';
}).join(',') + '}';
var paramJSONFormat;
try {
paramJSONFormat = JSON.parse(params);
}catch(e) {
paramJSONFormat = {};
}
return paramJSONFormat;
}
function getUrlParameter(key) {
var params = getUrlParameterMap();
return params && params[key];
}
function removeStyleSheetRules(cssFileName, selectorText) {
var d = window.document || document;
if(!d) return null;
var sheets = d.styleSheets;
var sheet, rule;
var fileExp = new RegExp('(' + cssFileName + '\\.css)$', 'i');
for(var i = 0; i < sheets.length; i++) {
sheet = sheets[i];
var href = sheet.href && sheet.href.indexOf('?') > -1 ? sheet.href.split('?')[0] : sheet.href;
var cssRules = (fileExp.test(href) || cssFileName === href) && (sheet.cssRules || sheet.rules);
if(cssRules instanceof CSSRuleList) {
for (var j = 0; j < cssRules.length; j++) {
rule = cssRules[j];
var ruleSelector = rule.selectorText && rule.selectorText.trim();
if(ruleSelector && (ruleSelector === selectorText) ) {
// console.log(ruleSelector);
sheet.deleteRule(j);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment