Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
* 各種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.
  • Loading branch information
takuya-o committed Jan 26, 2018
1 parent 680139e commit 51e2c25
Show file tree
Hide file tree
Showing 6 changed files with 657 additions and 644 deletions.
64 changes: 25 additions & 39 deletions AutoPatchWork.safariextension/includes/AutoPatchWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,6 @@
}

if (window.chrome) {
window.addEventListener('AutoPatchWork.load.from.page', load_for_chrome, false);
window.addEventListener('AutoPatchWork.error.from.page', load_error_for_chrome, false);
request = request_for_chrome;
}
if ((next.host && next.host !== location.host) || (next.protocol && next.protocol !== location.protocol)) {
Expand Down Expand Up @@ -320,10 +318,6 @@
window.removeEventListener('AutoPatchWork.DOMNodeInserted', restore_setup, false);
window.removeEventListener('AutoPatchWork.state', state, false);
window.removeEventListener('beforeunload', savePosition, false);
if (window.chrome) {
window.removeEventListener('AutoPatchWork.load.from.page', load_for_chrome, false);
window.removeEventListener('AutoPatchWork.error.from.page', load_error_for_chrome, false);
}

if (status.bottom && status.bottom.parentNode) {
status.bottom.parentNode.removeChild(status.bottom);
Expand Down Expand Up @@ -532,39 +526,21 @@
loading = true;
}
var url = state.nextURL = next.href || next.getAttribute('href') || next.action || next.getAttribute('action') || next.value || next.getAttribute('value');
var s = document.createElement('script');
s.textContent = '(' + function (url) {
var x = new XMLHttpRequest();
x.onload = function () {
if (!x.getResponseHeader('Access-Control-Allow-Origin')) {
dispatch_message_event('AutoPatchWork.load.from.page', {responseText: x.responseText, url: url});
} else {
x.onerror();
}
};
x.onerror = function () {
dispatch_message_event('AutoPatchWork.error.from.page', {message: 'request failed. status:' + x.status});
};
x.open('GET', url, true);
x.overrideMimeType('text/html; charset=' + document.characterSet);
x.send(null);
function dispatch_message_event(name, data, o) {
o || (o = {});
var ev = document.createEvent('MessageEvent');
ev.initMessageEvent(name, o.canBubble || false, o.cancelable || false, data, o.origin || location.origin, o.id || Date.now(), o.source || window);
window.dispatchEvent(ev);
}
} + ')("' + url + '");';
document.head.appendChild(s);
document.head.removeChild(s);
}

function load_for_chrome(evt) {
dispatch_event('AutoPatchWork.load', {response: {responseText: evt.data.responseText}, url: evt.data.url});
}

function load_error_for_chrome(evt) {
dispatch_event('AutoPatchWork.error', {message: evt.data.message});
var x = new XMLHttpRequest();
x.onload = function () {
if (location.origin === (new URL(x.responseURL)).origin) {
dispatch_event('AutoPatchWork.load', {response: x, url: x.responseURL});
} else {
x.onerror();
}
};
x.onerror = function () {
dispatch_event('AutoPatchWork.error', {message: 'request failed. status:' + x.status});
};
x.open('GET', url, true);
x.overrideMimeType('text/html; charset=' + document.characterSet);
x.send(null);
}

function request_iframe() {
Expand Down Expand Up @@ -676,13 +652,19 @@
append_point.insertBefore(root, insert_point);
var docHeight = documentHeight();
var docs = get_next_elements(htmlDoc);
var elementHeight = pageElementHeight(docs[docs.length - 1]);
var first = docs[0];
if (!first) {
dispatch_event('AutoPatchWork.terminated', {message: 'The next page\'s pageElement was empty.'});
htmlDoc = null;
return;
}
docs.forEach(function (doc, i, docs) {
Array.prototype.forEach.call(doc.querySelectorAll('img'), function(img) {
if (!img.getAttribute('src').match(/(^https?:\/\/|^data:|^\/)/)) {
img.setAttribute('src', next.getAttribute('href').replace(/\/[\w:%#\$&\?\(\)~\.=\+\-]*$/, '/') + img.getAttribute('src'));
}
});
var insert_node = append_point.insertBefore(document.importNode(doc, true), insert_point);
var mutation = {
targetNode: insert_node,
Expand All @@ -699,7 +681,7 @@
docs[i] = insert_node;
});
if (status.bottom) status.bottom.style.height = Root.scrollHeight + 'px';
if (docHeight === documentHeight()) {
if (elementHeight === pageElementHeight(docs[docs.length - 1]) && docHeight === documentHeight()) {
return dispatch_event('AutoPatchWork.error', {message: 'missing next page contents'});
}
next = get_next(htmlDoc);
Expand All @@ -724,6 +706,10 @@
function documentHeight() {
return Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
}

function pageElementHeight(element) {
return element.parentNode.scrollHeight;
}

function createXHTML(str) {
return new DOMParser().parseFromString(str, 'application/xhtml+xml');
Expand Down
39 changes: 16 additions & 23 deletions AutoPatchWork.safariextension/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ init_barcss();
var version = '', Manifest;
IconData = {};

get_manifest(function (_manifest) {
Manifest = _manifest;
version = _manifest.version;
});
get_manifest();

function siteinfoFromCache() {
var data = Strg.get('siteinfo_wedata', true);
Expand Down Expand Up @@ -163,7 +160,7 @@ var ToggleCode = '(' + (function () {
document.dispatchEvent(ev);
}).toString() + ')();';

g.chrome && chrome.extension.onMessage.addListener(handleMessage);
g.chrome && chrome.runtime.onMessage.addListener(handleMessage);

g.safari && safari.application.addEventListener("message", function (evt) {
var name = evt.name;
Expand Down Expand Up @@ -373,32 +370,28 @@ function Siteinfo(info) {
Strg.set('siteinfo_wedata', {siteinfo: siteinfo, timestamp: timestamp.toLocaleString()}, {day: 1});
applyCustom();
}
function get_manifest(callback) {
var url = './manifest.json';
function load_resource(url, callback) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function () {
callback(JSON.parse(xhr.responseText));
callback(xhr.responseText);
};
xhr.open('GET', url, true);
xhr.send(null);
}
function get_manifest() {
load_resource('./manifest.json', function (content) {
var _manifest = JSON.parse(content);
Manifest = _manifest;
version = _manifest.version;
});
}
function init_css() {
var url = 'css/AutoPatchWork.css';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function() {
AutoPatchWork.save_css(xhr.responseText);
};
xhr.send(null);
load_resource('css/AutoPatchWork.css', AutoPatchWork.save_css);
}
function init_barcss() {
var url = 'css/AutoPatchWork.bar.css';
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onload = function() {
AutoPatchWork.barcss = xhr.responseText;
};
xhr.send(null);
load_resource('css/AutoPatchWork.bar.css', function (content) {
AutoPatchWork.barcss = content;
});
}
function UpdateSiteinfo(callback, error_back, force) {
var sso = 'http://os0x.heteml.jp/ss-onet/json/wedataAutoPagerizeSITEINFO.json';
Expand Down
Loading

0 comments on commit 51e2c25

Please sign in to comment.