From 807b32792a877c5eac7ec9ae65987a43986b4aa4 Mon Sep 17 00:00:00 2001 From: qarkai Date: Wed, 7 Dec 2016 01:21:45 +0300 Subject: [PATCH 1/2] Reduce duplicate code --- .../js/background.js | 31 +++++++------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/AutoPatchWork.safariextension/js/background.js b/AutoPatchWork.safariextension/js/background.js index 82ca94b..74214c7 100644 --- a/AutoPatchWork.safariextension/js/background.js +++ b/AutoPatchWork.safariextension/js/background.js @@ -125,7 +125,8 @@ init_barcss(); var version = '', Manifest; IconData = {}; -get_manifest(function (_manifest) { +get_manifest(function (content) { + var _manifest = JSON.parse(content); Manifest = _manifest; version = _manifest.version; }); @@ -373,32 +374,24 @@ 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(callback) { + load_resource('./manifest.json', callback); +} 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'; From f7f79219f9f07595151607ac74658145fa52ea99 Mon Sep 17 00:00:00 2001 From: qarkai Date: Wed, 7 Dec 2016 09:29:12 +0300 Subject: [PATCH 2/2] Remove callback parameter from get_manifest() --- AutoPatchWork.safariextension/js/background.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/AutoPatchWork.safariextension/js/background.js b/AutoPatchWork.safariextension/js/background.js index 74214c7..de6b6e1 100644 --- a/AutoPatchWork.safariextension/js/background.js +++ b/AutoPatchWork.safariextension/js/background.js @@ -125,11 +125,7 @@ init_barcss(); var version = '', Manifest; IconData = {}; -get_manifest(function (content) { - var _manifest = JSON.parse(content); - Manifest = _manifest; - version = _manifest.version; -}); +get_manifest(); function siteinfoFromCache() { var data = Strg.get('siteinfo_wedata', true); @@ -382,8 +378,12 @@ function load_resource(url, callback) { }; xhr.send(null); } -function get_manifest(callback) { - load_resource('./manifest.json', callback); +function get_manifest() { + load_resource('./manifest.json', function (content) { + var _manifest = JSON.parse(content); + Manifest = _manifest; + version = _manifest.version; + }); } function init_css() { load_resource('css/AutoPatchWork.css', AutoPatchWork.save_css);