Skip to content

Instantly share code, notes, and snippets.

@vladkosinov
Created November 26, 2014 15:38
Show Gist options
  • Save vladkosinov/9da50e24e26b5a900849 to your computer and use it in GitHub Desktop.
Save vladkosinov/9da50e24e26b5a900849 to your computer and use it in GitHub Desktop.
changeAndPersist
(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