Skip to content
This repository was archived by the owner on Jul 27, 2024. It is now read-only.

Commit c33907e

Browse files
committed
Merge branch 'dev'
2 parents b338a9c + f983ff5 commit c33907e

File tree

19 files changed

+303
-209
lines changed

19 files changed

+303
-209
lines changed

src/background/sync/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,11 @@ define('sync', function (require, _exports, module) {
326326
};
327327
xhr.send(options.body);
328328

329-
function requestError(reason) {
329+
function requestError() {
330330
reject({
331331
url: options.url,
332332
status: xhr.status,
333-
reason: reason || xhr.responseText,
333+
xhr: xhr,
334334
});
335335
}
336336
});

src/background/sync/onedrive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ define('sync_onedrive', function (require, _exports, _module) {
106106
return getMeta()
107107
.catch(function (res) {
108108
if (res.status === 404) {
109-
var header = res.getResponseHeader('WWW-Authenticate') || '';
109+
var header = res.xhr.getResponseHeader('WWW-Authenticate') || '';
110110
if (/^Bearer realm="OneDriveAPI"/.test(header)) {
111111
return _this.refreshToken().then(getMeta);
112112
} else {

src/background/utils/tester.js

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ define('utils/tester', function (_require, exports, _module) {
1111
if (custom.exclude) exc = exc.concat(custom.exclude);
1212
var ok = !mat.length && !inc.length;
1313
// @match
14-
ok = ok || mat.length && function (urlParts) {
15-
return mat.some(function (str) {
16-
return matchTest(str, urlParts);
17-
});
18-
}(url.match(match_reg));
14+
ok = ok || mat.length && function (test) {
15+
return mat.some(test);
16+
}(matchTester(url));
1917
// @include
2018
ok = ok || inc.some(function (str) {
2119
return autoReg(str).test(url);
@@ -38,30 +36,41 @@ define('utils/tester', function (_require, exports, _module) {
3836
return str2RE(str); // String with wildcards
3937
}
4038

41-
var match_reg = /(.*?):\/\/([^\/]*)\/(.*)/;
42-
function matchTest(str, urlParts) {
43-
if (str == '<all_urls>') return true;
44-
var parts = str.match(match_reg);
45-
var ok = !!parts;
46-
// scheme
47-
ok = ok && (
39+
function matchTester(url) {
40+
function matchScheme(rule, data) {
4841
// exact match
49-
parts[1] == urlParts[1]
42+
if (rule == data) return 1;
5043
// * = http | https
51-
|| parts[1] == '*' && /^https?$/i.test(urlParts[1])
52-
);
53-
// host
54-
ok = ok && (
44+
if (rule == '*' && /^https?$/i.test(data)) return 1;
45+
return 0;
46+
}
47+
function matchHost(rule, data) {
5548
// * matches all
56-
parts[2] == '*'
49+
if (rule == '*') return 1;
5750
// exact match
58-
|| parts[2] == urlParts[2]
51+
if (rule == data) return 1;
5952
// *.example.com
60-
|| /^\*\.[^*]*$/.test(parts[2]) && str2RE(parts[2]).test(urlParts[2])
61-
);
62-
// pathname
63-
ok = ok && str2RE(parts[3]).test(urlParts[3]);
64-
return ok;
53+
if (/^\*\.[^*]*$/.test(rule)) {
54+
// matches the specified domain
55+
if (rule.slice(2) == data) return 1;
56+
// matches subdomains
57+
if (str2RE(rule).test(data)) return 1;
58+
}
59+
return 0;
60+
}
61+
function matchPath(rule, data) {
62+
return str2RE(rule).test(data);
63+
}
64+
var RE = /(.*?):\/\/([^\/]*)\/(.*)/;
65+
var urlParts = url.match(RE);
66+
return function (str) {
67+
if (str == '<all_urls>') return true;
68+
var parts = str.match(RE);
69+
return !!parts
70+
&& matchScheme(parts[1], urlParts[1])
71+
&& matchHost(parts[2], urlParts[2])
72+
&& matchPath(parts[3], urlParts[3]);
73+
};
6574
}
6675

6776
exports.testURL = testURL;

src/cache.js

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,32 @@ define('cache', function (require, _exports, module) {
3030
var BaseView = cache.BaseView = Backbone.View.extend({
3131
initialize: function () {
3232
var _this = this;
33-
if (_this.templateUrl)
34-
_this.__gotTemplate = cache.get(_this.templateUrl)
35-
.then(function (fn) {
36-
_this.templateFn = fn;
37-
});
33+
_this.subviews = {data: {}};
34+
_this.childViews = [];
35+
if (_this.templateUrl) {
36+
_this.__gotTemplate = cache.get(_this.templateUrl)
37+
.then(function (fn) {
38+
_this.templateFn = fn;
39+
});
40+
}
3841
_.bindAll(_this, 'render', 'postrender');
3942
_this.render();
4043
},
44+
clear: function () {
45+
var _this = this;
46+
if (_this.childViews.length) {
47+
_this.childViews.forEach(function (view) {
48+
view.remove();
49+
});
50+
_this.childViews = [];
51+
}
52+
},
53+
remove: function () {
54+
var _this = this;
55+
_this.clear();
56+
_this.undelegateEvents();
57+
Backbone.View.prototype.remove.call(_this);
58+
},
4159
_render: function () {
4260
this.$el.html(this.templateFn());
4361
},
@@ -55,6 +73,27 @@ define('cache', function (require, _exports, module) {
5573
_.features.isHit(node.dataset.feature) || node.classList.add('feature');
5674
});
5775
},
76+
loadSubview: function (name, factory, selector) {
77+
var _this = this;
78+
var view;
79+
var subviews = _this.subviews;
80+
view = subviews.data[name];
81+
if (!view) {
82+
view = factory();
83+
}
84+
var current = subviews.current;
85+
if (name !== current) {
86+
var currentView = subviews.data[current];
87+
if (currentView) {
88+
currentView.remove();
89+
subviews.data[current] = null;
90+
}
91+
}
92+
subviews.data[subviews.current = name] = view;
93+
var $el = selector ? _this.$(selector) : _this.$el;
94+
$el.html(view.render().el);
95+
return view;
96+
},
5897
getValue: function (target) {
5998
var key = target.dataset.id;
6099
var value;
@@ -79,6 +118,30 @@ define('cache', function (require, _exports, module) {
79118

80119
BaseView.prototype.postrender.call(window);
81120

121+
cache.BaseRouter = Backbone.Router.extend({
122+
initialize: function (selector) {
123+
var _this = this;
124+
_this.views = {data: {}};
125+
_this.$root = $(selector);
126+
},
127+
loadView: function (name, factory) {
128+
var _this = this;
129+
var views = _this.views;
130+
var view = views.data[name];
131+
if (!view) view = views.data[name] = factory();
132+
if (name !== views.current) {
133+
var currentView = views.data[views.current];
134+
if (currentView) {
135+
currentView.remove();
136+
views.data[views.current] = null;
137+
}
138+
views.data[views.current = name] = view;
139+
}
140+
_this.$root.html(view.el);
141+
return view;
142+
},
143+
});
144+
82145
!function () {
83146
var xhr = new XMLHttpRequest;
84147
xhr.open('GET', '/icons/sprite.svg', true);

src/options/app.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
define('app', function (require, exports, _module) {
22
var MainView = require('views/Main');
33
var ConfirmView = require('views/Confirm');
4-
var EditView = require('views/Edit');
54
var MessageView = require('views/Message');
65
var models = require('models');
6+
var cache = require('cache');
77
zip.workerScriptsPath = '/lib/zip.js/';
88

99
_.sendMessage = _.getMessenger({});
1010
_.showMessage = function (options) {
1111
new MessageView(options);
1212
};
1313

14-
var App = Backbone.Router.extend({
14+
var App = cache.BaseRouter.extend({
1515
routes: {
1616
'': 'renderMain',
1717
'main/:tab': 'renderMain',
1818
'confirm/:url': 'renderConfirm',
1919
'confirm/:url/:from': 'renderConfirm',
2020
},
2121
renderMain: function (tab) {
22-
exports.scriptList || initMain();
23-
this.view = new MainView(tab);
22+
this.loadView('main', function () {
23+
initMain();
24+
return new MainView;
25+
}).loadTab(tab);
2426
},
25-
renderConfirm: function (url, _from) {
26-
this.view = new ConfirmView(url, _from);
27-
},
28-
renderEdit: function (id) {
29-
this.view = new EditView(id);
27+
renderConfirm: function (url, referer) {
28+
this.loadView('confirm', function () {
29+
return new ConfirmView;
30+
}).initData(url, referer);
3031
},
3132
});
32-
var app = new App();
33+
var app = new App('#app');
3334
Backbone.history.start() || app.navigate('', {trigger: true, replace: true});
3435

3536
$(document).on('click', '[data-feature]', function (e) {

src/options/style.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ aside img {
9191
border-right: 1px solid darkgray;
9292
overflow-y: hidden;
9393
}
94-
#tab > header {
94+
.content > header {
9595
height: 30px;
9696
line-height: 30px;
9797
padding: 0 .5rem;
@@ -147,6 +147,9 @@ input[disabled] ~ * {
147147
padding: 20px;
148148
overflow-y: auto;
149149
}
150+
.no-pad {
151+
padding: 0;
152+
}
150153
fieldset.title {
151154
margin-top: 20px;
152155
padding: 10px;

src/options/templates/confirm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<button id=btnClose data-i18n=buttonClose></button>
99
</div>
1010
<h1><span data-i18n=labelInstall></span> - <span data-i18n=extName></span></h1>
11-
<div id=url class=ellipsis title="<%- it.url %>"><%- it.url %></div>
11+
<div id=url class=ellipsis></div>
1212
<div id=msg class=ellipsis></div>
1313
</div>
1414
<div class=frame-body>

src/options/templates/main.html

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
<div class="main">
2-
<aside>
3-
<img src="/icons/icon_64.png">
4-
<h2 data-i18n=extName></h2>
5-
<div class="line">2013-2016</div>
6-
<hr>
7-
<div class=sidemenu>
8-
<a href="#main/installed" <%= it.tab == 'main' ? 'class="active"' : '' %> data-i18n=sideMenuInstalled></a>
9-
<a href="#main/settings" <%= it.tab == 'settings' ? 'class="active"' : '' %> data-feature="settings">
10-
<span data-i18n=sideMenuSettings class="feature-text"></span>
11-
</a>
12-
<a href="#main/about" <%= it.tab == 'about' ? 'class="active"' : '' %> data-i18n=sideMenuAbout></a>
13-
</div>
14-
</aside>
15-
<div id="tab"></div>
16-
</div>
1+
<aside>
2+
<img src="/icons/icon_64.png">
3+
<h2 data-i18n=extName></h2>
4+
<div class="line">2013-2016</div>
5+
<hr>
6+
<div class=sidemenu>
7+
<a href="#main/installed" <%= it.tab == 'main' ? 'class="active"' : '' %> data-i18n=sideMenuInstalled></a>
8+
<a href="#main/settings" <%= it.tab == 'settings' ? 'class="active"' : '' %> data-feature="settings">
9+
<span data-i18n=sideMenuSettings class="feature-text"></span>
10+
</a>
11+
<a href="#main/about" <%= it.tab == 'about' ? 'class="active"' : '' %> data-i18n=sideMenuAbout></a>
12+
</div>
13+
</aside>
14+
<div id="tab"></div>
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
<div class="content">
2-
<h1>
3-
<span data-i18n=labelAbout></span>
4-
<small>v<%= it.version %></small>
5-
</h1>
6-
<div class=line data-i18n=extDescription></div>
7-
<div class=line>
8-
<label data-i18n=labelRelated></label>
9-
<span data-i18n=anchorSupportPage></span> |
10-
<a href=http://gerald.top/donate target=_blank data-i18n=labelDonate></a> |
11-
<a href=https://github.com/Violentmonkey/Violentmonkey-mx/issues target=_blank data-i18n=labelFeedback></a>
12-
</div>
13-
<div class=line>
14-
<label data-i18n=labelAuthor></label>
15-
<span data-i18n=anchorAuthor></span>
16-
</div>
17-
<div class=line>
18-
<label data-i18n=labelTranslator></label>
19-
<span data-i18n=anchorTranslator></span>
20-
</div>
21-
<div class=line>
22-
<label data-i18n=labelCurrentLang></label>
23-
<span id="currentLang"><%= navigator.language %></span> |
24-
<a href=http://cotrans.geraldl.net target=_blank>
25-
Help with translation
26-
</a>
27-
</div>
1+
<h1>
2+
<span data-i18n=labelAbout></span>
3+
<small>v<%= it.version %></small>
4+
</h1>
5+
<div class=line data-i18n=extDescription></div>
6+
<div class=line>
7+
<label data-i18n=labelRelated></label>
8+
<span data-i18n=anchorSupportPage></span> |
9+
<a href=http://gerald.top/donate target=_blank data-i18n=labelDonate></a> |
10+
<a href=https://github.com/Violentmonkey/Violentmonkey-mx/issues target=_blank data-i18n=labelFeedback></a>
11+
</div>
12+
<div class=line>
13+
<label data-i18n=labelAuthor></label>
14+
<span data-i18n=anchorAuthor></span>
15+
</div>
16+
<div class=line>
17+
<label data-i18n=labelTranslator></label>
18+
<span data-i18n=anchorTranslator></span>
19+
</div>
20+
<div class=line>
21+
<label data-i18n=labelCurrentLang></label>
22+
<span id="currentLang"><%= navigator.language %></span> |
23+
<a href=http://cotrans.geraldl.net target=_blank>
24+
Help with translation
25+
</a>
2826
</div>

0 commit comments

Comments
 (0)