I am trying to write a Greasemonkey script to insert text into the Firefox search box that is next to the address bar.
I wonder if it is possible, if yes then how?
You cant do that.
That's because addons (in your case GreaseMonkey) run in a privileged environment which isn't available to userscripts and if this privilage was given to the user (i mean javascript) anyone could write a script and whenever you visit their website, they could do anything with your browser (or even your device!). So in other words Firefox (or formally browser) elements are unaccessible from js.
You could try to redirect your webpage to something like this: https://www.google.com/search?q=YOUR+SEARCH+QUERY .
Some parts were quoted from the comments of the question.
Related
I would like to run some userscripts to backup data.
The same scripts could be used on a variety of websites.
Scripts are basically the same, only some configuration changes from one script to another (what to scrape on the page, and where to save it).
Scripts will not alter the page in any way, just read it then call some REST API with the data
I do not want these scripts to be loaded on every web page, as they won't alter them, and depending on the page there is only one I'd like to run anyway.
So is there a way to launch these scripts directly from the browser (Firefox) ? From a bookmark or something ? Basically I want to click a button and have the script run like if I was running it from the js console.
Best I found for now is the "#run-at context-menu" directive of Tampermonkey. My script appears in a TamperMonkey context menu and is run on click.
However this menu is loaded on every page (#run-at context-menu ignores the #include directive and is applied everywhere), I'm not sure of the performance consequences, and it might be inconvenient if I end up with lots of scripts.
I guess I could also modify my scripts to be run on specific pages so that they add a floating button or something. But I'd rather not modify the pages, and it would be inconvenient on pages where I'd like to have several possible scripts.
I remember using a Greasemonkey script that added options on the context menu a long while ago. Would that be possible with Tampermonkey, implementing an equivalent of the #run-at context-menu myself that would only work on some pages ?
A more native way would be best, but I'm open to options.
Basically I want to click a button and have the script run like if I was running it from the js console.
From above, I assume the userscript does not use any GM API or use #require since those are not available in JS console.
If that is the case, FireMonkey has a feature to inject script (or CSS) from the toolbar popup.
After saving a script and disabling it (so it doesn't run automatically) or enabling on sites that the script MUST run, users can select the script in the toolbar icon popup and click the button to inject the script in the active tab.
For temporary scripts, FireMonkey also has a Scratchpad that you can paste JS (or CSS) into and run on any webpage by clicking the button. FireMonkey remembers the last pasted data so that it can be reused.
Note: Except TM that alters the CSP of websites, other managers are bound by the webpage CSP.
Turns out there's a function for that: https://wiki.greasespot.net/GM.registerMenuCommand
Your script just needs to declare a function, call GM.registerMenuCommand("label", your_function), and it becomes available on click in the GM/TM menu.
Contrary to the other answer this means you can use #require.
Contrary to the #run-at context-menu this means you can use #match to only apply it to the intended websites
Notes:
GM_registerMenuCommand in TamperMonkey
Needs the #grant to use the function
I am making a firefox pluggin and I want to open a "topbar" on a few websites. Realy, it would be a few informations about the curent page a link back to my own website. What would be te best way to do that ?
My first idea was to use content script, but that seems to be a very bad practice. I also read about panels, here are my questions :
How can I add my pannel just under the adressbar ?
How can I only open in it on the website I need ?
thx.
Using content script is completely fine.
It is modern, simple, less-code, more compatible way
to add top-panel to some web pages.
Also, code of content script is not injected to the web page, it just uses the dom and context; page script has no access (if you do not provide it explicit) to content script.
The only possible disadvantage is that panel would not look like native part of the browser.
If I convienced you to use content script:
The module you really need in your plugin page-mod
Using Add-on Builder you make have your plugin in a day
So I know this might sound crazy, as it is technically a security concern which I understand. So I'm just trying to find out if there's any ideas on how to handle something like this.
Anyways, long story short, I was told to look into figuring out a possible way to scrape information from another browser window/tab. I have been asked to do this because, and I know this sounds crazy too, but the users of our website are incompetent enough to not be able to copy/paste and or type correctly something from a different website. I know it's tough for some to have to have several things in their workflow, but this is basically what they do: Go to their first website (after logging in) and bring up a record with information on it...including an identification number. Then, the user should take that number and go to the second website, our website (after logging in), and type it that number in a textbox (and eventually do some other stuff). But we have found that getting that identification number from the first website to ours is difficult for them. Some copy/paste correctly, some copy/paste too much text from the page, some write it down on paper then type it in our website, and some just seem to have trouble visually "copying" the number from site to site.
What I was thinking was that this could happen: the user would have already brought up the record on the first site, then they would come to ours. They could click a button, and that would run whatever I/we here come up with, that goes and finds the other browser window, finds the specific text needed, and puts it in our textbox. Sounds simple, right? HA.
The first website is not owned or managed by us in any way, otherwise this might be a little easier.
A little bit of background information: unfortunately, I'm technically targeting IE >= 10 through 9, so if there's a solution just for this (why I tagged vbscript), then that's great. If there's a broader solution (like with an applet or browser extensions... http://crossrider.com/ ), then that's even better, but not important. If it helps, we already have a hidden applet on the page that accesses the OS (yes, it has the mayscript attribute on the element so it is able to), so I thought that could be something to incorporate with. Also, the way I expect to know which window/tab to access is by URL and/or document title - either will be very specific.
We cannot install stuff on the users' computers, at least something outside of the browser (like extensions). I'm not sure how browser extensions work, so I'm wondering if they'd need to be "installed".
I know of HTML5's postMessage, but it only has partial support in IE (and none in IE <= 7)...and the partial support refers to not including exactly what I might need. It also requires that the other website be listening (which we don't have control over, but technically might be possible to include). So it doesn't count :)
The things I found with Java are to possibly find the list of processes currently running, but I don't know how to access/control one. Especially how to access the browser's Document.
And vbscript...I just don't know. I don't know if it's just me, but I can't seem to find good documentation on it, so I'm not sure what can be done with it.
Even if I could get control of the other browser window, I don't know how I would get information from it (like the DOM).
I'm not looking for code, just ideas...I'll do the research. And although it may sound impossible, don't just brush it off because Javascript can't do it - I haven't.
UPDATE:
I ended up developing a browser extension with http://www.crossrider.com/ which wasn't ideal, but works.
You could use a bookmarklet for this ... the user would have to drag the bookmarklet into their bookmarks bar on their browser, but if doing that wasn't beyond your user's abilities/the technical restrictions you've mentioned, then you'd definitely be able to send the information you need back to your site that way.
You'd just need to give your users instructions to:
i) drag the bookmarklet into their bookmarks bar on their browser
ii) go to the website in question and click the bookmarklet
you could code the bookmarklet so that it would grab the info you need, and redirect the browser to your website. All done in one click.
I think you may be thinking about it in the wrong way when you talk about posting from one 'window' to another. You could write the bookmarklet so that it would do a http post of whatever information you wanted into your site from the other site, and it could also redirect the window that they were looking at when they clicked it (the other site) to your site. Or if, for some reason, you didn't want to redirect the the window that they had the 'other' site in to your site, then you could add a listener to your site so that once the bookmarklet had posted the info you require then the window with your displaying could automatically update. The first option would make more sense and be easier though.
Maybe to open the other site from button/link resided in your site using window.open() method?
Some web pages such as GMail and Reddit(with the Reddit Enhancement Suite) have useful keyboard shortcuts that I'd like to use. However, whenever I start typing on one of these pages, the first onkeypress event fires, but then the "Search for text when I start typing" search bar opens and blocks further keys.
I don't want to disable "Search for text when I start typing" as I use it on most other web pages. Is there any way to selectively disable it, or to make a keyboard shortcut/bookmarklet to toggle it?
To disable this in firefox, just go to "Options->General Tab->Browsing and disable "Search for text when I start typing". More info here . This is very useful in some cases, for example when you try to play WebGL games or when using pages like Gmail or Protonmail that have their own kb shortcuts.
UPDATED to version 73.0.1- In previous versions of Firefox this is in "Tools->Options->Advanced->General Tab" or in "Preferences->General->Browsing"
This is still an issue huh? I love this feature but It also bothers me every now and then. There are some pages that get it right. I never dug into how they do it. For instance:
zty.pe - JS browser typing game. Would be pretty bad if typing caused searching here. It actually captures the keys just when the game starts and NOT by default on the page.
That is not Firefox or any other browser feature. To do this, you have to write server and client side code.
Catch text that user types into input, and send it using preferably AJAX to server-side script. Then server side script should look up for matches in DB (some search engine), and return possible combinations. All you have to do on client side (JS) is to show returned results in some nice way - like in google - you can use for example simple html lists, but you have to code some css to make it look properly. Also nice feature is to code JS to work on up/down keys and enter for selecting element (it should also work for mouse).
It's not very simple to do by yourself, but you have now idea how to do it. You could also google for some scripts - surely there is something :)
Good luck!
I'm writing a Greasemonkey script that has a fair few user settings (just using GM_getValue and GM_setValue).
What I'd like to be able to do is create a settings page for the script, and add that to the #include-d sites. So, for example, it'd run on:
#include http://www.greasemonkeyedsite.com/*
#include about:myScriptConfig
Then the script would check the URL of the site it's being called for. If it's the about: one it'd create and display a settings page, otherwise it'd just run the script as usual.
I came up with this under the impression that you could type about:(anything) and it'd show up fine, with just the text following the about: as the page content. I remember this working last time I checked it, but that was years ago.
Seems to be that you can't just display arbitrary data by use of about:x any more, though. Firefox just displays a "The URL is not valid and cannot be loaded" error.
I know about the data: URI protocol, but it's not suitable as entering it manually into the address bar doesn't lead to its own page.
Is there some equivalent behaviour? Or am I going to have to just have a "settings" button on the top corner of greasemonkeyedsite.com that hides and shows a settings div?
If you have a permanent web site, you could make a URL there that becomes the Greasemonkey script's settings page. That could even be a convenient URL that allows the user to download the script if he does not already have it installed, and you can, that way, also offer the user a software update when a new version of your script is released. (Just have the Greasemonkey script check some "current version" part of the settings page.)
As mentioned by jnpcl, it is possible to create a chrome:// URI within the browser, but as I understand it, that requires a full-fledged Firefox add-on rather than just a Greasemonkey script.
You could use a designated URL on the affected site if you do not have a permanent web site, like http://www.greasemonekyedsite.com/myGreasemonkeySettingsPage. Your script could then strip out the parts of their 404 page it does not need, and then it could insert its list of settings within.