Skip to content

Instantly share code, notes, and snippets.

@kuntashov
Last active February 11, 2019 10:32
Show Gist options
  • Save kuntashov/72c53ae67d92a3800961496b521e4699 to your computer and use it in GitHub Desktop.
Save kuntashov/72c53ae67d92a3800961496b521e4699 to your computer and use it in GitHub Desktop.
Создает в шапке веб-клиента 1С кнопку для замены определенного текста на всей странице
(function() {
function replaceAllText(searchValue, replaceValue) {
// Поиск
var xResult,
node,
xpath = "//text()[contains(., '" + searchValue + "')]";
xResult = document.evaluate(
xpath,
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null);
// Замена
for (var i = 0; i < xResult.snapshotLength; i++) {
node = xResult.snapshotItem(i);
node.textContent = node.textContent.replace(searchValue, replaceValue);
}
}
function createReplaceButton(searchString, replaceString) {
var target = document.querySelector('.headerRightBox').children[0],
button = document.createElement('button');
button.innerHTML = "Заменить";
target.parentNode.insertBefore(button, target);
button.onclick = function() {
replaceAllText(searchString, replaceString);
}
}
// Вызывать лучше после загрузки всей страницы, идеально в window.onload
createReplaceButton("Сравнить", "Compare");
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment