Skip to content
DitherSky edited this page Jul 6, 2016 · 27 revisions

AutoPatchWork for Opera Wiki

Пример интеграции с другими скриптами:
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')]", 
"nextMask": "http://test.net/pages/|1",
"disableSeparator":"true",
"forceAddressChange_comment":"this parameter inverts extension's global setting",
"forceAddressChange":"true",
"forceIframe":"false",
"cssPatch": ".page img { min-height:500px; }",
"jsPatch": "document.addEventListener('AutoPatchWork.pageloaded', function (event) { updThumbs(); }, false);"
},
...
]
Clone this wiki locally