I've used this this in several large scripts without a problem. If I recall
correctly it works also in Opera. That was actually the reason I resorted to
this solution with one script. But maybe I changed some things over time.
// Script injection
function inject_script() {
var script =
document.getElementsByTagName('head')[0].appendChild(document.createElement('script'));
script.setAttribute('type', 'text/javascript');
return
script.textContent=inject_script.toString().replace(/[\s\S]*"\$1"\);([\s\S]*)}/,"$1");
alert("inserted");
}
inject_script();
You can probably call the script right away by appending the last "}" with
braces "()". But in some cases it's handy to have the actual call in a
different spot.
ArmEagle
On Sun, Apr 3, 2011 at 11:47 AM, edzep <[email protected]> wrote:
>
> Wow, I've got it working!
> (but, still need a wee bit of advice)
>
> It's a beautiful thing. Re-studied GreaseSpot, and took note of script
> injection. Followed a snippet on userscripts (from this page:
> http://userscripts.org/topics/51137).
>
> Script appears below. I'm currently pulling in the entire .js file for the
> color picker, off the server. For several reasons, I need to get the .js
> code bundled into my script. (One potential problem could result from
> server
> lag and execution times.)
>
> My question is, can anyone recommend a clever way of making a string of the
> 256-line .js file, so that I won't have to manually escape all of the quote
> marks?
>
> // ==UserScript==
>
> // @name Color Test
>
> // @description test color picker
>
> // ==/UserScript==
>
>
>
> // Start
>
>
>
> (function() {
>
>
>
> function insertJavascript() {
>
> var scriptNode = document.createElement("script");
>
> scriptNode.setAttribute("src",
> "http://www.dematte.at/jscolorXS/jscolor_src.js");
>
> scriptNode.setAttribute("type", "text/javascript");
>
>
>
> var headerNode = document.getElementsByTagName("head")[0];
>
> headerNode.appendChild(scriptNode);
>
> }
>
>
>
> function colortest_Run(){
>
> insertJavascript();
>
>
>
> var colorDiv = document.createElement("div");
>
>
>
> colorDiv.innerHTML = "<h2>Demo:</h2><p><input class='color'
> value='#FF0000'
> /><input class='color' value='#C0F399' /><input class='color'
> value='#34CA00' /></p>";
>
>
>
> colorDiv.id = "colorPanel";
>
> colorDiv.style.position = "fixed";
>
> colorDiv.style.display = "block";
>
> colorDiv.style.backgroundColor = "#F3F3F3";
>
> colorDiv.style.borderStyle = "solid";
>
> colorDiv.style.zIndex = "104";
>
>
>
> //--- place new panel into HTML
>
>
>
> var findbody = document.evaluate("//body", document, null,
> XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
>
> var item = findbody.snapshotItem(0);
>
> item.insertBefore(colorDiv, item.firstChild);
>
> }
>
>
>
> colortest_Run();
>
>
>
> })();
>
> // End
>
>
>
> --
> View this message in context:
> http://old.nabble.com/trouble-getting-color-picker-functional-tp31302802p31306286.html
> Sent from the GreaseMonkey List mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "greasemonkey-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/greasemonkey-users?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/greasemonkey-users?hl=en.