Created
November 26, 2014 15:38
-
-
Save vladkosinov/9da50e24e26b5a900849 to your computer and use it in GitHub Desktop.
changeAndPersist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (window) { | |
function change(selector, content) { | |
var elements = window.document.querySelectorAll(selector); | |
for (var i = 0; i < elements.length; i++) { | |
var element = elements[i]; | |
element.innerHTML = content; | |
} | |
} | |
var changeAndPersist = function (elements, condition) { | |
if (condition() || window.localStorage.getItem("changeAndPersist")) { | |
window.localStorage.setItem("changeAndPersist", true); | |
} else { | |
return false; | |
} | |
for (var i = 0; i < elements.length; i++) { | |
var element = elements[i]; | |
var selector = element['selector']; | |
var content = element['content']; | |
change(selector, content); | |
} | |
}; | |
if (typeof define === 'function' && define.amd) { | |
define(function () { | |
return changeAndPersist; | |
}); | |
} else if (typeof exports === 'object') { | |
if (typeof module === 'object' && typeof module.exports === 'object') { | |
exports = module.exports = changeAndPersist; | |
} | |
exports.changeAndPersist = changeAndPersist; | |
} else { | |
window.changeAndPersist = changeAndPersist; | |
} | |
})(typeof window === 'undefined' ? this : window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment