aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--twittperator.js78
-rw-r--r--twittperator/twsidebar-expand-url.tw24
2 files changed, 66 insertions, 36 deletions
diff --git a/twittperator.js b/twittperator.js
index 76e4023..651afb0 100644
--- a/twittperator.js
+++ b/twittperator.js
@@ -1770,6 +1770,9 @@ let INFO =
}
xhr.send(null);
}, // }}}
+ getPluginNameFromFile: function(file) { // {{{
+ return file.leafName.replace(/\..*/, "");
+ }, // }}}
}; // }}}
let Twittperator = { // {{{
activitySummary: function(id) { // {{{
@@ -1838,20 +1841,33 @@ let INFO =
let (name = file.leafName.replace(/\..*/, "").replace(/-/g, "_"))
liberator.globalVariables["twittperator_plugin_" + name];
- function loadPluginFromDir(checkGV) {
+ function loadPluginFromDir(checkGV, candidates) {
return function(dir) {
dir.readDirectory().forEach(function(file) {
- if (/\.tw$/.test(file.path) && (!checkGV || isEnabled(file)))
- Twittperator.sourceScriptFile(file);
+ if (/\.tw$/.test(file.path) && (!checkGV || isEnabled(file))) {
+ if (candidates) {
+ self._plugins.candidates[Utils.getPluginNameFromFile(file)] = file;
+ } else {
+ Twittperator.sourceScriptFile(file);
+ }
+ }
});
}
}
+ let self = this;
+ this._plugins = {
+ candidates: {},
+ loaded: {}
+ };
+
ChirpUserStream.clearPluginData();
TrackingStream.clearPluginData();
- io.getRuntimeDirectories("plugin/twittperator").forEach(loadPluginFromDir(true));
- io.getRuntimeDirectories("twittperator").forEach(loadPluginFromDir(false));
+ for (let [, c] in Iterator([true, false])) {
+ io.getRuntimeDirectories("plugin/twittperator").forEach(loadPluginFromDir(true, c));
+ io.getRuntimeDirectories("twittperator").forEach(loadPluginFromDir(false, c));
+ }
}, // }}}
lookupUser: function(users) { // {{{
function showUsersInfo(json) { // {{{
@@ -2082,31 +2098,39 @@ let INFO =
});
}, // }}}
sourceScriptFile: function(file) { // {{{
- // XXX 悪い子向けのハックです。すみません。 *.tw ファイルを *.js のように読み込みます。
- let script = liberator.plugins.contexts[file.path];
-
- let originalPath = file.path;
- let hackedPath = originalPath.replace(/\.tw$/, ".js");
-
- let ugly = {
- __noSuchMethod__: function (name, args) originalPath[name].apply(originalPath, args),
- toString: function() {
- function isFile (caller) {
- if (!caller)
- return false;
- if (caller === io.File)
- return true;
- return isFile(caller.caller);
- }
- return isFile(arguments.callee.caller) ? originalPath : hackedPath;
- }
- };
+ let self = this;
+
+ if (self._plugins.loaded[Utils.getPluginNameFromFile(file)])
+ return true;
+
+ let stdScript = liberator.plugins.contexts[file.path];
try {
- io.source(ugly, false);
+ let script = Script(file);
+
+ script.__context__.require = function (names) {
+ if (!(names instanceof Array))
+ names = [names];
+ names.forEach(function (name) {
+ if (self._plugins.loaded[name])
+ return;
+ let lib = self._plugins.candidates[name];
+ if (lib)
+ self.sourceScriptFile(lib);
+ else
+ throw "Not found twittperator plugin: " + name;
+ });
+ };
+
+ let uri = services.get("io").newFileURI(file);
+ let suffix = '?' + encodeURIComponent(services.get("UUID").generateUUID().toString());
+
+ liberator.loadScript(uri.spec + suffix, script);
+ self._plugins.loaded[Utils.getPluginNameFromFile(file)] = script;
+
} finally {
- if (script)
- liberator.plugins[script.NAME] = script;
+ if (stdScript)
+ liberator.plugins[stdScript.NAME] = stdScript;
}
}, // }}}
withProtectedUserConfirmation: function(check, actionName, action) { // {{{
diff --git a/twittperator/twsidebar-expand-url.tw b/twittperator/twsidebar-expand-url.tw
index ae84110..8eee68d 100644
--- a/twittperator/twsidebar-expand-url.tw
+++ b/twittperator/twsidebar-expand-url.tw
@@ -1,3 +1,6 @@
+
+require('twsidebar');
+
(function () {
let Config = liberator.globalVariables.twittperator_sidebar_expand_url_config || {
host: ['ff.im', 'is.gd', 't.co', 'bit.ly', 'j.mp', 'htn.to', 'goo.gl', 'ow.ly'],
@@ -33,8 +36,13 @@
function sidebar ()
document.getElementById('sidebar')._contentWindow.document;
- function twsText (id)
- sidebar().getElementById(id).childNodes[1].childNodes[3].childNodes[3].firstChild;
+ function twsText (id) {
+ try {
+ return sidebar().getElementById(id).childNodes[1].childNodes[3].childNodes[3].firstChild;
+ } catch (e) {
+ return void 0;
+ }
+ }
function scroll () {
let tws = sidebar().getElementById('tw-anekos-sb-home-list');
@@ -48,13 +56,11 @@
expandURL(urls[i].expanded_url, function (eUrl , expand) {
tweet.text = tweet.text.replace(sUrl, eUrl);
let fUrl = expand ? sUrl : eUrl;
- let interval = setInterval(function () {
- if (twsText(id)) {
- twsText(id).textContent = escapeBreakers(twsText(id).textContent.replace(fUrl, Config.filter(eUrl)));
- scroll();
- clearInterval(interval)
- }
- }, 100);
+ let e = twsText(id);
+ if (e) {
+ e.textContent = escapeBreakers(e.textContent.replace(fUrl, Config.filter(eUrl)));
+ scroll();
+ }
});
}
}