Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce duplicate code #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 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 @@ -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