forked from greasemonkey/greasemonkey
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
On "new script", with valid script on clipbard, just install it.
- Loading branch information
Showing
3 changed files
with
55 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Components.utils.import('resource://greasemonkey/parseScript.js'); | ||
Components.utils.import('resource://greasemonkey/remoteScript.js'); | ||
Components.utils.import('resource://greasemonkey/util.js'); | ||
|
||
const EXPORTED_SYMBOLS = ['installScriptFromSource']; | ||
|
||
function installScriptFromSource(aSource, aCallback) { | ||
var remoteScript = new RemoteScript(); | ||
var script = parse(aSource); | ||
var tempFileName = cleanFilename(script.name, 'gm_script') + '.user.js'; | ||
var tempFile = GM_util.getTempFile(remoteScript._tempDir, tempFileName); | ||
GM_util.writeToFile(aSource, tempFile, function() { | ||
// install this script | ||
remoteScript.setScript(script, tempFile); | ||
remoteScript.install(); | ||
// and fire up the editor! | ||
GM_util.openInEditor(script); | ||
}); | ||
if (aCallback) aCallback(); | ||
} |
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,10 +1,39 @@ | ||
Components.utils.import('resource://greasemonkey/parseScript.js'); | ||
Components.utils.import('resource://greasemonkey/util.js'); | ||
|
||
const EXPORTED_SYMBOLS = ['newUserScript']; | ||
|
||
const ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] | ||
const gClipboard = Components.classes["@mozilla.org/widget/clipboard;1"] | ||
.getService(Components.interfaces.nsIClipboard); | ||
const gWindowWatcher = Components | ||
.classes["@mozilla.org/embedcomp/window-watcher;1"] | ||
.getService(Components.interfaces.nsIWindowWatcher); | ||
|
||
function newUserScript(aWin) { | ||
ww.openWindow(aWin, | ||
"chrome://greasemonkey/content/newscript.xul", null, | ||
"chrome,dependent,centerscreen,resizable,dialog", null); | ||
var clipText = ''; | ||
try { | ||
var transferable = Components.classes["@mozilla.org/widget/transferable;1"] | ||
.createInstance(Components.interfaces.nsITransferable); | ||
transferable.addDataFlavor('text/unicode'); | ||
gClipboard.getData(transferable, gClipboard.kGlobalClipboard); | ||
var str = new Object(), strLen = new Object(); | ||
transferable.getTransferData('text/unicode', str, strLen); | ||
if (str) { | ||
str = str.value.QueryInterface(Components.interfaces.nsISupportsString); | ||
clipText = str.data.substring(0, strLen.value / 2); | ||
} | ||
} catch (e) { | ||
dump('Error reading clipboard:\n' + e + '\n'); | ||
} | ||
|
||
// If there is a valid script with metadata on the clipboard ... | ||
if (clipText && extractMeta(clipText)) { | ||
// ... just install it! | ||
GM_util.installScriptFromSource(clipText); | ||
} else { | ||
// Otherwise do GUIfied script creation. | ||
gWindowWatcher.openWindow(aWin, | ||
"chrome://greasemonkey/content/newscript.xul", null, | ||
"chrome,dependent,centerscreen,resizable,dialog", null); | ||
} | ||
} |