Skip to content

Commit 51e2c25

Browse files
committed
Squashed commit of the following:
* 各種update Build.rbを完成させた Resolve "GitHub上の各forkから最強版を作る" Merge remote-tracking branch 'origin/buildScript' into 4-github-fork Version up and remove http://os0x.heteml.jp/ access permission * Merge remote-tracking branch 'mono0x/develop' into 4-github-fork Use chrome.runtime.getBackgroundPage cc9b9c3 chrome.extension.getBackgroundPage()だとイベントページが再起動しないのでchrome.runtime.getBackgroundPage()を使う mono0x@cc9b9c3 Use chrome.runtime.onMessage dea8523 イベントページ対応のためにruntime.onMessageを使う mono0x@dea8523 * Merge remote-tracking branch 'xKerman/fix-use-response-url' into 4-github-fork use xhr.responseURL to prevent cross-origin request 5357f81 xKerman@5357f81 stop using XMLHttpRequest in web page context 1be037eページにscriptを埋め込んで次のページを取っていたが、Scriptで取るように変更する (上の変更も無くなる) xKerman@1be037e * Merge remote-tracking branch 'qarkai/master' into 4-github-fork Pull Request 13 Reduce duplicate code os0x#13 * Merge remote-tracking branch 'dlwr/resolve-img-relative-path' into 4-github-fork Pull Request 11 format relative path of img element to absolute path os0x#11 * Merge remote-tracking branch 't-f-m/patch-1' into 4-github-fork Pull Request 10 ページ高さの判定を安全寄りに os0x#10 commit a6af8fb Author: Takuya Ono <[email protected]> Date: Mon Jun 19 23:00:00 2017 +0900 fixed #1 SITEINFO管理でのデータ取得をss-o.netからwedata.netに変えた commit f7f7921 Author: qarkai <[email protected]> Date: Wed Dec 7 09:29:12 2016 +0300 Remove callback parameter from get_manifest() commit 807b327 Author: qarkai <[email protected]> Date: Wed Dec 7 01:21:45 2016 +0300 Reduce duplicate code commit aaeea49 Merge: 36fda48 dea8523 Author: mono <[email protected]> Date: Sun Jun 7 02:29:36 2015 +0900 Merge branch 'use-chrome-runtime' into develop commit dea8523 Author: mono <[email protected]> Date: Sun Jun 7 02:29:19 2015 +0900 Use chrome.runtime.onMessage commit 36fda48 Merge: d4e3bf2 cc9b9c3 Author: mono <[email protected]> Date: Sun Jun 7 01:17:00 2015 +0900 Merge branch 'chrome-runtime-getbackgroundpage' into develop commit cc9b9c3 Author: mono <[email protected]> Date: Sun Jun 7 01:15:36 2015 +0900 Use chrome.runtime.getBackgroundPage commit f626741 Author: dlwr <[email protected]> Date: Sun Nov 23 17:42:43 2014 +0900 Update AutoPatchWork.js fix bug commit 9edac19 Author: dlwr <[email protected]> Date: Tue Nov 18 14:21:38 2014 +0900 format relative path of img element to absolute path commit 4090781 Author: t-f-m <[email protected]> Date: Fri Sep 19 09:08:45 2014 +0900 ページ高さの判定を安全寄りに commit 1be037e Author: X Kerman <[email protected]> Date: Sun Sep 14 15:25:24 2014 +0900 stop using XMLHttpRequest in web page context commit 5357f81 Author: X Kerman <[email protected]> Date: Sun Sep 14 12:58:25 2014 +0900 use `xhr.responseURL` to prevent cross-origin request commit d6c1f19 Author: Takuya Ono <[email protected]> Date: Tue Mar 4 01:20:53 2014 +0900 Create crxmake command line build script.
1 parent 680139e commit 51e2c25

File tree

6 files changed

+657
-644
lines changed

6 files changed

+657
-644
lines changed

AutoPatchWork.safariextension/includes/AutoPatchWork.js

Lines changed: 25 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@
174174
}
175175

176176
if (window.chrome) {
177-
window.addEventListener('AutoPatchWork.load.from.page', load_for_chrome, false);
178-
window.addEventListener('AutoPatchWork.error.from.page', load_error_for_chrome, false);
179177
request = request_for_chrome;
180178
}
181179
if ((next.host && next.host !== location.host) || (next.protocol && next.protocol !== location.protocol)) {
@@ -320,10 +318,6 @@
320318
window.removeEventListener('AutoPatchWork.DOMNodeInserted', restore_setup, false);
321319
window.removeEventListener('AutoPatchWork.state', state, false);
322320
window.removeEventListener('beforeunload', savePosition, false);
323-
if (window.chrome) {
324-
window.removeEventListener('AutoPatchWork.load.from.page', load_for_chrome, false);
325-
window.removeEventListener('AutoPatchWork.error.from.page', load_error_for_chrome, false);
326-
}
327321

328322
if (status.bottom && status.bottom.parentNode) {
329323
status.bottom.parentNode.removeChild(status.bottom);
@@ -532,39 +526,21 @@
532526
loading = true;
533527
}
534528
var url = state.nextURL = next.href || next.getAttribute('href') || next.action || next.getAttribute('action') || next.value || next.getAttribute('value');
535-
var s = document.createElement('script');
536-
s.textContent = '(' + function (url) {
537-
var x = new XMLHttpRequest();
538-
x.onload = function () {
539-
if (!x.getResponseHeader('Access-Control-Allow-Origin')) {
540-
dispatch_message_event('AutoPatchWork.load.from.page', {responseText: x.responseText, url: url});
541-
} else {
542-
x.onerror();
543-
}
544-
};
545-
x.onerror = function () {
546-
dispatch_message_event('AutoPatchWork.error.from.page', {message: 'request failed. status:' + x.status});
547-
};
548-
x.open('GET', url, true);
549-
x.overrideMimeType('text/html; charset=' + document.characterSet);
550-
x.send(null);
551-
function dispatch_message_event(name, data, o) {
552-
o || (o = {});
553-
var ev = document.createEvent('MessageEvent');
554-
ev.initMessageEvent(name, o.canBubble || false, o.cancelable || false, data, o.origin || location.origin, o.id || Date.now(), o.source || window);
555-
window.dispatchEvent(ev);
556-
}
557-
} + ')("' + url + '");';
558-
document.head.appendChild(s);
559-
document.head.removeChild(s);
560-
}
561529

562-
function load_for_chrome(evt) {
563-
dispatch_event('AutoPatchWork.load', {response: {responseText: evt.data.responseText}, url: evt.data.url});
564-
}
565-
566-
function load_error_for_chrome(evt) {
567-
dispatch_event('AutoPatchWork.error', {message: evt.data.message});
530+
var x = new XMLHttpRequest();
531+
x.onload = function () {
532+
if (location.origin === (new URL(x.responseURL)).origin) {
533+
dispatch_event('AutoPatchWork.load', {response: x, url: x.responseURL});
534+
} else {
535+
x.onerror();
536+
}
537+
};
538+
x.onerror = function () {
539+
dispatch_event('AutoPatchWork.error', {message: 'request failed. status:' + x.status});
540+
};
541+
x.open('GET', url, true);
542+
x.overrideMimeType('text/html; charset=' + document.characterSet);
543+
x.send(null);
568544
}
569545

570546
function request_iframe() {
@@ -676,13 +652,19 @@
676652
append_point.insertBefore(root, insert_point);
677653
var docHeight = documentHeight();
678654
var docs = get_next_elements(htmlDoc);
655+
var elementHeight = pageElementHeight(docs[docs.length - 1]);
679656
var first = docs[0];
680657
if (!first) {
681658
dispatch_event('AutoPatchWork.terminated', {message: 'The next page\'s pageElement was empty.'});
682659
htmlDoc = null;
683660
return;
684661
}
685662
docs.forEach(function (doc, i, docs) {
663+
Array.prototype.forEach.call(doc.querySelectorAll('img'), function(img) {
664+
if (!img.getAttribute('src').match(/(^https?:\/\/|^data:|^\/)/)) {
665+
img.setAttribute('src', next.getAttribute('href').replace(/\/[\w:%#\$&\?\(\)~\.=\+\-]*$/, '/') + img.getAttribute('src'));
666+
}
667+
});
686668
var insert_node = append_point.insertBefore(document.importNode(doc, true), insert_point);
687669
var mutation = {
688670
targetNode: insert_node,
@@ -699,7 +681,7 @@
699681
docs[i] = insert_node;
700682
});
701683
if (status.bottom) status.bottom.style.height = Root.scrollHeight + 'px';
702-
if (docHeight === documentHeight()) {
684+
if (elementHeight === pageElementHeight(docs[docs.length - 1]) && docHeight === documentHeight()) {
703685
return dispatch_event('AutoPatchWork.error', {message: 'missing next page contents'});
704686
}
705687
next = get_next(htmlDoc);
@@ -724,6 +706,10 @@
724706
function documentHeight() {
725707
return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
726708
}
709+
710+
function pageElementHeight(element) {
711+
return element.parentNode.scrollHeight;
712+
}
727713

728714
function createXHTML(str) {
729715
return new DOMParser().parseFromString(str, 'application/xhtml+xml');

AutoPatchWork.safariextension/js/background.js

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,7 @@ init_barcss();
125125
var version = '', Manifest;
126126
IconData = {};
127127

128-
get_manifest(function (_manifest) {
129-
Manifest = _manifest;
130-
version = _manifest.version;
131-
});
128+
get_manifest();
132129

133130
function siteinfoFromCache() {
134131
var data = Strg.get('siteinfo_wedata', true);
@@ -163,7 +160,7 @@ var ToggleCode = '(' + (function () {
163160
document.dispatchEvent(ev);
164161
}).toString() + ')();';
165162

166-
g.chrome && chrome.extension.onMessage.addListener(handleMessage);
163+
g.chrome && chrome.runtime.onMessage.addListener(handleMessage);
167164

168165
g.safari && safari.application.addEventListener("message", function (evt) {
169166
var name = evt.name;
@@ -373,32 +370,28 @@ function Siteinfo(info) {
373370
Strg.set('siteinfo_wedata', {siteinfo: siteinfo, timestamp: timestamp.toLocaleString()}, {day: 1});
374371
applyCustom();
375372
}
376-
function get_manifest(callback) {
377-
var url = './manifest.json';
373+
function load_resource(url, callback) {
378374
var xhr = new XMLHttpRequest();
375+
xhr.open('GET', url, true);
379376
xhr.onload = function () {
380-
callback(JSON.parse(xhr.responseText));
377+
callback(xhr.responseText);
381378
};
382-
xhr.open('GET', url, true);
383379
xhr.send(null);
384380
}
381+
function get_manifest() {
382+
load_resource('./manifest.json', function (content) {
383+
var _manifest = JSON.parse(content);
384+
Manifest = _manifest;
385+
version = _manifest.version;
386+
});
387+
}
385388
function init_css() {
386-
var url = 'css/AutoPatchWork.css';
387-
var xhr = new XMLHttpRequest();
388-
xhr.open('GET', url, true);
389-
xhr.onload = function() {
390-
AutoPatchWork.save_css(xhr.responseText);
391-
};
392-
xhr.send(null);
389+
load_resource('css/AutoPatchWork.css', AutoPatchWork.save_css);
393390
}
394391
function init_barcss() {
395-
var url = 'css/AutoPatchWork.bar.css';
396-
var xhr = new XMLHttpRequest();
397-
xhr.open('GET', url, true);
398-
xhr.onload = function() {
399-
AutoPatchWork.barcss = xhr.responseText;
400-
};
401-
xhr.send(null);
392+
load_resource('css/AutoPatchWork.bar.css', function (content) {
393+
AutoPatchWork.barcss = content;
394+
});
402395
}
403396
function UpdateSiteinfo(callback, error_back, force) {
404397
var sso = 'http://os0x.heteml.jp/ss-onet/json/wedataAutoPagerizeSITEINFO.json';

0 commit comments

Comments
 (0)