bookmarklet

Find and replace in a webpage using javascript [duplicate]

℡╲_俬逩灬. 提交于 2019-11-29 07:25:30
This question already has an answer here: Replace many text terms, using Tampermonkey, without affecting URLs and not looking for classes or ids 1 answer What I want to do is replace all instances of 'foo' in a webpage with 'bar' in a JS bookmarklet/greasemonkey script. How can I do this? I suppose jQuery works, as there're hacks to include those in both bookmarklets and greasemonkey scripts. Josh Stodola This script iterates through each element in the document and replaces every instance of foo with bar . The gi modifiers on the regex make it do a global , case-insensitive search. var els =

Find all text nodes

别来无恙 提交于 2019-11-29 05:59:46
I'm trying to write a bookmarklet that calls the function doSomething(textNode) on all instances of visible text on the document. doSomething() , just for fun, replaces every word with "derp" by replacing the textContent of the textNode passed into it. However, this makes some textNodes that are empty to have words in them, so it breaks the web page. Is there a way to call doSomething() on only every textNode that has words in it? function recurse(element) { if (element.childNodes.length > 0) for (var i = 0; i < element.childNodes.length; i++) recurse(element.childNodes[i]); if (element

Is it possible to load multiple different version of jQuery on the same page?

纵然是瞬间 提交于 2019-11-29 04:46:53
I'm making a bookmarklet which will load jQuery if the object is not found. The loading will check on the version of jQuery. The code is like: (function(){ var myBkl = { loadScript: function(src) { if(window.jQuery && window.jQuery.fn.jquery == '1.3.2'){ return; } var s = document.createElement('script'); s.setAttribute('src', src); s.setAttribute('type', 'text/javascript'); document.getElementsByTagName('head')[0].appendChild(s); }, whenLoaded: function(callback){ if (typeof(window.jQuery) !== 'undefined' && window.jQuery.fn.jquery == '1.3.2') { callback(window.jQuery); } else { setTimeout(

Using Javascript to Open a New Page and Populate Form Values There

早过忘川 提交于 2019-11-29 02:42:19
I am using JavaScript in a bookmarklet to populate form elements on a website: javascript:var f = document.forms[0]; f.getElementsByTagName('input')[0].value = 'myname'; f.getElementsByTagName('input')[1].value = 'mypassword'; f.getElementsByTagName('input')[2].click This works. However what I would like to create is a bookmarklet so that it opens the target page, and populates the values there; however it seems that onces the page is loaded, other JavaScript codes are not executed. So, the following doesn't work. javascript:window.location("mywebsite");var f = document.forms[0]; f

Bookmarklet to edit current URL

流过昼夜 提交于 2019-11-29 01:07:03
问题 I'm looking for a simple bookmarklet to take the current URL of my website and refresh it with a couple of changes. For example: Take the current page: http://www.example.com/pages/ and change it to: https://admin.example.com/pages/ then load that new URL. I tried searching for a bookmarklet that can do this but I couldn't find one. Can anyone point me in the right direction? Even a bookmarklet that does something like this that I can edit to suit my needs. 回答1: Just change window.location ,

Sending Text Cross Domain By Bookmarklet

有些话、适合烂在心里 提交于 2019-11-29 00:30:01
I need a user to navigate to a certain page that has a certain div full of useful text. Then click my bookmarklet and send the text in that div back to my server, which is different from the current domain. I have successfully inserted jQuery on the bookmarklet click and selected the text. Now I need to figure out a way to send that text cross domain to my server. I tried JSONP with jQuery and my text is too long for the url. My second idea was to open up a new window and load a page from my domain, and then somehow insert the selected text into the new window, after which the user could click

unable to run an external javascript using a bookmarklet

浪子不回头ぞ 提交于 2019-11-29 00:18:27
Totally newbie about JS. I need to use an external script which modifies some elements in the current page accessing it as a bookmarklet. If I modify the html source code of the web page inserting the following < script > lines: s=document.createElement('script'); s.type='text/javascript'; s.src='script.js'; document.getElementsByTagName('head')[0].appendChild(s); it works fine. But if I create a javascript: bookmarklet with the same lines, I obtain a blank page with the following string: [object HTMLScriptElement] whereas, if I create a bookmarklet adding the line void(null); to previous ones

easier bookmarklet development

我的未来我决定 提交于 2019-11-29 00:08:33
问题 Here's how I make develop a bookmarklet: I write a javascript function, pass that to Bookmarklet Builder to make a bookmarklet, add the bookmarklet to my browser, load my test webpage, test the bookmarklet, and then something doesn't work, so I try to find what's wrong and change my javascript function accordingly and the tedious cycle starts again. How can I make this cycle less tedious? 回答1: use the firebug console to develop and test your function, and turn it into a bookmarklet once you

Ajax call from Bookmarklet

丶灬走出姿态 提交于 2019-11-29 00:07:34
I am trying to create a bookmarklet that, upon clicking, would request some information from the user (a url and a couple other fields in this case) and then send that data to a php page on my server and then display the result. I would like to do an Ajax call for this so that I don't actually redirect to the new page, just get the data but I assume I would run into the "Same Origin Policy" limitation of Ajax.... is there any known way of basically doing the same thing? Also, what would be the best way to pass the parameters? I already have a mechanism in place to recieve the parameters as a

How to remove 'http://' from a URL in JavaScript [duplicate]

女生的网名这么多〃 提交于 2019-11-28 17:46:25
This question already has an answer here: taking off the http or https off a javascript string 11 answers I have run into an odd situation. I'm writing a JavaScript bookmarklet that will allow users to click and share external websites to our website very easily and quickly. It simply get's the title, page URL, and if they've selected any text on the page, it grabs it too. The problem is it doesn't work with external domains for some reason, so if we use it internally we end up with a share window with the URL formatted like this: http://internaldomain.com/sharetool.php?shareid=http:/