forked from to/tombloo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
via https://github.com/polygonplanet/tombloo/blob/74e5cc003a08197d8a5e62beeca5e7eddbe2ca31/tombloo.service.actions.installpatch.fix.js * Move openInActionBase from actions.js to utility.js * Update Gruntfile.js Thanks, polygonplanet!
- Loading branch information
Showing
3 changed files
with
127 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,85 @@ | ||
Tombfix.Service.actions = new Repository([ | ||
{ | ||
type : 'context', | ||
icon : 'chrome://tombfix/skin/tombloo_16.png', | ||
name : getMessage('label.action.installPatch'), | ||
check : function(ctx){ | ||
// GitHubでかつraw以外のリンクの場合は除外する | ||
// FIXME: より簡易にインストールできるように | ||
var url = ctx.linkURL; | ||
return ctx.onLink && | ||
(createURI(url).fileExtension == 'js') && | ||
!(/github\.com/.test(url) && !/\/raw\//.test(url)); | ||
}, | ||
execute : function(ctx){ | ||
var self = this; | ||
|
||
// ファイルタイプを取得しチェックする | ||
var url; | ||
return request(ctx.linkURL).addCallback(function(res){ | ||
if(!/^text\/.*(javascript|plain)/.test(res.channel.contentType)){ | ||
alert(getMessage('message.install.invalid')); | ||
return; | ||
} | ||
|
||
var res = input({ | ||
'message.install.warning' : null, | ||
'label.install.agree' : false, | ||
}, 'message.install.warning'); | ||
if(!res || !res['label.install.agree']) | ||
return; | ||
|
||
return download(ctx.linkURL, getPatchDir()).addCallback(function(file){ | ||
// 異常なスクリプトが含まれているとここで停止する | ||
reload(); | ||
|
||
notify(self.name, getMessage('message.install.success'), notify.ICON_INFO); | ||
}); | ||
}); | ||
}, | ||
}, | ||
|
||
{ | ||
type : 'menu,context', | ||
name : getMessage('label.action.changeAccount'), | ||
execute : function(){ | ||
openDialog('chrome://tombfix/content/library/login.xul', 'resizable,centerscreen'); | ||
}, | ||
}, | ||
{ | ||
type : 'menu,context', | ||
name : '----', | ||
}, | ||
{ | ||
type : 'menu,context', | ||
icon : 'chrome://tombfix/skin/tombloo_16.png', | ||
name : getMessage('label.action.tombfixOptions'), | ||
execute : function(){ | ||
openDialog('chrome://tombfix/content/prefs.xul', 'resizable,centerscreen'); | ||
}, | ||
}, | ||
]); | ||
/* global request, Tombfix, Repository, getMessage, createURI, alert, input */ | ||
/* global download, getPatchDir, reload, notify, openDialog */ | ||
|
||
var openInActionBase = { | ||
check : function(ctx){ | ||
return true; | ||
}, | ||
execute : function(ctx){ | ||
var app = this.getFile(getPrefValue(this.prefKey)); | ||
if(!app){ | ||
while(true){ | ||
var path = prompt(this.prompt); | ||
if(path === null) | ||
return; | ||
|
||
app = this.getFile(path); | ||
if(app){ | ||
setPrefValue(this.prefKey, path); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
try{ | ||
new Process(app).run(false, [ctx.href], 1); | ||
}catch(e){ | ||
alert(e); | ||
setPrefValue(this.prefKey, ''); | ||
} | ||
}, | ||
getFile : function(path){ | ||
try{ | ||
var file = getLocalFile(path); | ||
return file.exists() && file.isFile() && file; | ||
}catch(e){} | ||
}, | ||
} | ||
(function executeActions(global) { | ||
'use strict'; | ||
|
||
global.Actions = Tombfix.Service.actions = new Repository([ | ||
// FIXME: より簡易にインストールできるように | ||
{ | ||
type : 'context', | ||
icon : 'chrome://tombfix/skin/tombloo_16.png', | ||
name : getMessage('label.action.installPatch'), | ||
check : function check(ctx) { | ||
if (ctx.onLink) { | ||
let uri = createURI(ctx.linkURL); | ||
|
||
return uri.fileExtension === 'js' && (( | ||
// GitHubでかつraw以外のリンクの場合は除外する | ||
/^(?:gist\.)?github\.com$/.test(uri.host) && | ||
/\/raw\//.test(uri.path) | ||
) || uri.host === 'raw.github.com'); | ||
} | ||
}, | ||
execute : function execute(ctx) { | ||
// ファイルタイプを取得しチェックする | ||
return request(ctx.linkURL).addCallback(res => { | ||
var result; | ||
|
||
if (res.channel.contentType !== 'text/plain') { | ||
alert(getMessage('message.install.invalid')); | ||
|
||
return; | ||
} | ||
|
||
result = input({ | ||
'message.install.warning' : null, | ||
'label.install.agree' : false, | ||
}, 'message.install.warning'); | ||
|
||
if (!(result && result['label.install.agree'])) { | ||
return; | ||
} | ||
|
||
return download(ctx.linkURL, getPatchDir()).addCallback(() => { | ||
// 異常なスクリプトが含まれているとここで停止する | ||
reload(); | ||
notify( | ||
this.name, | ||
getMessage('message.install.success'), | ||
notify.ICON_INFO | ||
); | ||
}); | ||
}); | ||
} | ||
}, | ||
|
||
{ | ||
type : 'menu,context', | ||
name : getMessage('label.action.changeAccount'), | ||
execute : function execute() { | ||
openDialog( | ||
'chrome://tombfix/content/library/login.xul', | ||
'resizable,centerscreen' | ||
); | ||
} | ||
}, | ||
|
||
{ | ||
type : 'menu,context', | ||
name : '----' | ||
}, | ||
|
||
{ | ||
type : 'menu,context', | ||
icon : 'chrome://tombfix/skin/tombloo_16.png', | ||
name : getMessage('label.action.tombfixOptions'), | ||
execute : function execute() { | ||
openDialog( | ||
'chrome://tombfix/content/prefs.xul', | ||
'resizable,centerscreen' | ||
); | ||
} | ||
} | ||
]); | ||
}(this)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters