-
Notifications
You must be signed in to change notification settings - Fork 2
Home
DitherSky edited this page Aug 13, 2016
·
27 revisions
Пример интеграции с другими скриптами:
Scripts integration example:
Старый метод:
Old method:
var onLoad = function onLoad(node, url) {
... here we have newly loaded content as "node" ...
var exampleSelQuery = node.querySelectorAll(selectors);
var exampleXPath = document.evaluate('//div[@id="body"]/*[@class="sexy"]', node, null, 9, null);
... fixing something on that page ...
}
// Let's parse auto-added pages with our script
window.addEventListener('AutoPatchWork.DOMNodeInserted', function (e) {
onLoad(e.target, e.target['data-apw-url']);
}, false);
Более новый метод (первый - отдельный скрипт, второй в поле jsPatch в менеджере SITEINFO):
Newer method (first separate script secod using jsPatch in SITEINFO manager):
// ==UserScript==
// @include https://example.com/*
// ==/UserScript==
function handleNewPageLoad(event) {
/* your code parsing event.detail.url or event.detail.htmlDoc or neither but before page appending*/
}
document.addEventListener('AutoPatchWork.load', handleNewPageLoad, false);
document.addEventListener('AutoPatchWork.pageloaded', function (event) { siteObject.loadThumbnails(); }, false);
Формат своих паттернов аналогичен оригинальному массиву SIEINFO в JSON:
Custom patterns are in JSON format that's similar to original SIEINFO array:
[
...
{
"pageElement":"id('test')/div[2]/table//tr",
"removeElement":"//nav[contains(concat(' ', @class, ' '), ' advertis ')]",
"url":"^http://test\\.net/(pages|catalog)/",
"nextLink":"//div[@class='test-pager']/a[text()='\\u00bb' or contains(., 'Next')]",
"prevLink":"//div[@class='test-pager']/a[contains(text(), 'Previous')]",
"alternatively_to_nextLink_-_nextMask": "http://test.net/pages/|1",
"disableSeparator":"true",
"forceAddressChange_comment":"this parameter inverts extension's global setting",
"forceAddressChange":true,
"forceIframe":false,
"paused": true,
"id": "1000000009",
"id_comment": "unique id is required for paused/reversed to work",
"reversed": true,
"cssPatch": ".page img { min-height:500px; }",
"jsPatch": "document.addEventListener('AutoPatchWork.pageloaded', function (event) { updThumbs(); }, false);"
},
...
]