JavaScript - Help With Chromium Bookmarklet! (insert Text At Cursor)
I'm not very well versed in javascript. I'm trying to make a bookmarklet that when I click it will either append text to what I've already written or insert the predefined text at the cursor's position in a textarea. Also the browser I'm trying to do this on is Chromium.
Here's what I have: Code: javascript:void((function(){document.getElementsByTagName('textarea')[0].value='ಠ_ಠ'})()) ...but this of course changes the entire value of the text field to: ಠ_ಠ ...rather than appending or inserting at the cursor position. I'm guessing append would be the simplest, though cursor position would be most efficient. So if you can help in anyway, please do! Thanks. Similar TutorialsI have a WYSIWYG text area and I want to insert combo-box' value at current cursor location of the WYSIWYG text area. I have a simple textarea where the value is inserting on combo-box clicking. But when I do integrate both files, the functionality wont work. I have both scripting files..
I'm trying to write a function that is similar to the ctrl+f functionality you get in IE, where you have a search string and when you click 'next' the whole string if matched is highlighted by the cursor. This works fine for inputs and text areas using the following code: Code: function setCaretPos(obj, start, end) { var range = obj.createTextRange(); range.moveStart('character', start); range.moveEnd('character', end - obj.value.length); range.select(); } But now I need to get it to work for normal text in a text node that is in the HTML/DOM. Is there an equivalent way of making the above method work for text in text nodes? Alternatively is there a way to make the browser (IE) at least focus on some text in a text node? (I could then highlight it with CSS styles). Sup yo, I need to add text in a <textarea>, but i can only append text at the end. Is there any way to add text to where the cursor is currently at? Code: function addCharm(var1) { var newtext = var1; document.lolform.inputtext.value += newtext; } And below i has sum buttonz that uses that function. So, again, how can I add text to where the I-beam is currently, instead of at the end? Thanks in advance. Hi all, I'm trying to get the cursor position to move to the end of the text within an editable iframe or div. I've been pointed to something called TextRange and have been reading up on it for days yet couldnt make sense of much (i'm still very new). what i'm trying to do is on a button click, the cursor will move to the end of the text in the iframe. any help or pointers would be greatly appreciated. thanks. im clueless when it comes to javascript, but this is what im trying to find: i have a page that has multiple text areas, i also have 4 links that when clicked i want to add some predefined text into the active text area the one with the text cursor in? The Hyperlinks: Code: <a href="#sc">Shift Changed</a> | <a href="#ol">On Leave</a> | <a href="#ot">OverTime</a> | <a href="#ss">ShiftSwap</a> The textareas: PHP Code: <td><textarea name=details$i rows=4 align=absmiddle cols=16 value="$details[$i]\">$details[$i]</textarea></td> as you can see the textareas are created on the fly based on a php array. would anyone be willing to put some code together for this? or even give me the basics on how i can get the active textarea's name so i can pass that to a script that inserts into a given field? Hi, I am wanting to insert text into a text area when a button or link is clicked. I know how to replace the whole lot in the text area, but I want it to insert text where the flashing cursor is in the text box. (Like Wikipedia) If any one can help, Then I will be very, very greatfull. Thank You. Hi there, I hope this is the right Forum for asking this. I'm trying to build a Bookmarklet for our Institute, which should work with our library repository. The idea is to consult a SQL search within the repository using the serial number of an article or book which is imported into the bookmarklet via getSelection. Then, after the search query is completed, the repository homepage prompts to the results page. This is where I get stuck. The bookmarklet should now simply show a prompt window saying: do you see a found result on this page? Yes or No. If the user clicks nno, the bookmarklet should forward to the import page, if Yes, the entry is already in the repository and the import is unneccessary. javascript:Qr=document.getSelection();if(!Qr)%7Bvoid(Qr=prompt('Please%20type%20repository&20Nr.:',' '))%7D;if(Qr)location.href='http://dali.biologie.uni-ulm.de/refbase-0.9.5/search.php?formType=sqlSearch&submit=&citeStyle=&citeOrder=&sqlQuery=SELECT+author%2C+title%2C+year% 2C+publication%2C+volume%2C+pages+FROM+refs+WHERE+doi+RLIKE+%22'+escape(Qr)+'%22+OR+notes+RLIKE+%22' +escape(Qr)+'%22+ORDER+BY+year+DESC%2C+author&showLinks=1&showRows=30&viewType=Web'; if(confirm('Is%20the%20article%20already%20in%20the%20repository?')) location.href='http://dali.biologie.uni-ulm.de/refbase-0.9.5/import_modify.php?formType=importID&submit=Import&showSource=1&sourceIDs='+escape(Qr) I hope this is not too confusing. Thanks to anyone for help, and have great holidays! Can someone tell me what I am doing wrong here... This returns "Button Not Found" Code: javascript:var nam="http://apps.facebook.com/onthefarm/giftaccept.php?senderId=547766125&gift=haitibackpack_item_single&timestamp=1285776944&ref=gift_accept_tab&key=6870697de39960508737349c7a3f1363%24%24ggM3T%2CPU2YKM2l0mNrM%28U%28b%21eHAoclFCBgwg49%21S34GWkEXxTekFN_Fkx5%2AUZPcNMEOj&signature=a86a9e11aab0051e3fde676a9abe4283&srcapp=FarmVille"; nam="actions["+nam.replace(/\&/g, "&")+"]"; var els=document.getElementsByName(nam); if(els.length == 0) alert("Button not found"); else els[0].click(); This prompts me to enter a URL...I enter the EXACT same URL as in the above example and it works fine, clicks the button which brings me to the desired page. Code: javascript:var nam=prompt('enter URL Please'); nam="actions["+nam.replace(/\&/g, "&")+"]"; var els=document.getElementsByName(nam); if(els.length == 0) alert("Button not found"); else els[0].click(); Thanks Edit: Before you ask...I've tried in Chrome, IE and Firefox. It does not appear to be an issue with the length of the JS. I get the same results as above regardless of which (valid) URL I use. Hi, I'm trying to make a JavaScript where when it's clicked, two alert input boxes appear and the user inputs two Facebook users' ID numbers. The script should then load an iFrame with: ttp://www.facebook.com/"+s+"?and="+s2+" Where "s" and "s2" are the variables. Why is the following not working? Code: if (typeof jQuery == 'undefined') { var jQ = document.createElement('script'); jQ.type = 'text/javascript'; jQ.onload=runthis, runthis2; jQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'; document.body.appendChild(jQ); } else { runthis(), runthis2(); } function runthis() { if ($("#wikiframe").length == 0) { var s = ""; s = getSelText(); if (s == "") { var s = prompt("Person 1"); } if ((s != "") && (s != null)) { $("body").append("\ function runthis2() { if ($("#wikiframe").length == 0) { var s2 = ""; if (s2 == "") { var s2 = prompt("Person 2'"); } if ((s2 != "") && (s2 != null)) { $("body").append("\ <div id='wikiframe'>\ <div id='wikiframe_veil' style=''>\ <p>Loading...</p>\ </div>\ <iframe src='http://www.facebook.com/"+s+"?and="+s2+"' onload=\"$('#wikiframe iframe').slideDown(500);\">Enable iFrames.</iframe>\ <style type='text/css'>\ #wikiframe_veil { display: none; position: fixed; width: 100%; height: 100%; top: 0; left: 0; background-color: rgba(255,255,255,.25); cursor: pointer; z-index: 900; }\ #wikiframe_veil p { color: black; font: normal normal bold 20px/20px Helvetica, sans-serif; position: absolute; top: 50%; left: 50%; width: 10em; margin: -10px auto 0 -5em; text-align: center; }\ #wikiframe iframe { display: none; position: fixed; top: 10%; left: 10%; width: 80%; height: 80%; z-index: 999; border: 10px solid rgba(0,0,0,.5); margin: -5px 0 0 -5px; }\ </style>\ </div>"); $("#wikiframe_veil").fadeIn(750); } } else { $("#wikiframe_veil").fadeOut(750); $("#wikiframe iframe").slideUp(500); setTimeout("$('#wikiframe').remove()", 750); } $("#wikiframe_veil").click(function(event){ $("#wikiframe_veil").fadeOut(750); $("#wikiframe iframe").slideUp(500); setTimeout("$('#wikiframe').remove()", 750); }); } function getSelText() { var s = ''; if (window.getSelection) { s = window.getSelection(); } else if (document.getSelection) { s = document.getSelection(); } else if (document.selection) { s = document.selection.createRange().text; } return s; } Hi, I am trying to build a bookmarklet to use on the swiss legislation website. All the pages are available in several languages and I want to be able to switch with one button from french to german and from german to french. As an example, the URLs are as follow for the same page: in French: http://www.admin.ch/ch/f/rs/311_0/index2.html in German: http://www.admin.ch/ch/d/sr/311_0/index2.html So I built quite easily two bookmarklets to switch FR-DE and DE-FR: Code: javascript: var str = window.location.pathname;str = str.replace("f/rs", "d/sr");window.location = str; Code: javascript: var str = window.location.pathname;str = str.replace("d/sr", "f/rs");window.location = str; But when I try to get a single script by using if/else, I cannot manage to have the "else" part working: Code: javascript: var str = window.location.pathname; if (location.pathname.indexOf("d/rs") < 0) { str = str.replace("f/rs", "d/sr"); window.location = str; } else { str = str.replace("d/sr", "f/rs"); window.location = str; } Thinking it might have to do with str.replace, I tried an easier variant, but even this one does not work, the "else" part is never called: Code: javascript: var str = window.location.pathname; if (location.pathname.indexOf("d/rs") < 0) { str = str.replace("f/rs", "d/sr"); window.location = str; } else { alert('no'); }; I would appreciate any help on the matter... thanks in advance, RJ Simple enough, one would think, but I'm rusty and haven't done this kind of thing in years. All I need to do is take the current page's url and replace/add a bit into the URL at the appropriate place. For Example, if this is the Current Page URL: Code: http://www.mysite.com/section/main.php?p=1 I want to be able to use the bookmarklet to change it to: Code: http://www.mysite.com/section2/main.php?p=1 This is all I've got for it so far. Probably botched that up too. Code: javascript:(function(){var%20a=document.URL.split("/section/");var%20newURL="www.mysite.com/section2/"+a;}) Hello all i need to be able to make small peace of js code that the user can drag to is IE browser and then invoke it on the page . Hi, I want to open a new window and then execute some js function on that window. My code looks like this: Code: windowObjectReference = window.open("http://some_page.html","name"); windowObjectReference = window.open("javascript:(some_function('param1');)","name"); Is it possible to do activate bookmarklet thru js on new window? Hey all - I need a java bookmarklet that does a real simple thing. I need to take the current URL (ie, where the user is when they click the bookmarklet) and append it to a static URL and return the text on the resulting page. For example: The user is at http://google.com The user clicks the bookmarklet. the bookmarklet takes http://google.com and appends it to http://example.com/outside_create.ph...ey=555&url=URL HERE where you see the URL HERE text. That PHP script echos a simple line of text (a shortened URL actually). Then I want that result from the outside_create.php file to be displayed in a window back to the user. Is this even possible? Basically I need to know how to append location.href to a static URL and how to get the resulting content from the static URL.. I'm trying to write a bookmarklet to automatically follow a specific link on a page without manually clicking or selecting the link. It's for the Facebook game Hatchlings. Each time I view someone's page to collect an egg, it has the following text: You found an egg! Add it to your basket. "Add it to your basket." is the clickable link, but has a different URL embedded in it each time I visit the page. Is there a way to create a bookmarklet to strip out the embedded URL and go to the link without actually clicking on "Add it to your basket." ? Thanks in advance for the help. hi guys, How could I make this useful dictionary bookmarklet open in a new window? javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.g etSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange( ).text));var%20e=(document.charset||document.characterSet);if(t!=''){location.href='http://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}; Its the "To English" bookmarklet as featured on lifehacker. Thanks! Hey guys, I have a question about sending text to a textarea. What I want is, if I click on a button, a text has to be sent to my textarea, which I obtain from my mysql database. This last thing I can do myself, but I do not know how to send the text to my textarea. I don't know nothing from AJAX yet, so I think it can be done with AJAX, but also with javascript I guess. Could someone point me in the right direction? Thanks! I have searched this forum for similar queries & have come up with this http://jsfiddle.net/defencedog/P33FR/ I don't know why this ain't working Hi, It would be easier to explain this if you play mafia wars (or any game that includes intra-game exchange of gifts/items between members) but the actual scripting doesn't require any knowledge of the game. Background Information Mafia Wars is a game on Facebook (and myspace, yahoo etc.) that among other things allows its players to send gifts to each other. Now because different people end up with more things of one type and are short of things of another type, the players have evolved a trading dynamic. Where x number of Item 1 is traded for y number of Item 2. A simple marketplace. And with this territory come scammers. Essentially a player who doesn't go through with his end of the deal. good player sends item to bad player. bad player removes good player from mafia and blocks him for ever contacting him through his facebook profile. This has given rise to my group, among many others, that lists these scammers (identified with their facebook profile ids) as they are reported every day. Now over time the list has grown and it has become difficult and unrealistic to expect people to know who is on the list and who is not. The Requirement A javascript bookmarklet (there are many already servicing different needs of the players) that sits on the browser and tells the user if the person he is about to trade with is a listed scammer or not. The Breakdown The user will click the bookmarklet when he is on the facebook profile of the person he is about to trade with. When clicked the script will pull the facebook profile id from the current page, and then scan a text file located on a third-party server and return with a pop-up box message that reports if the id is listed as a scammer or not. It should be pretty simple to do, except I don't know the first thing about javascript coding. So if there's anyone who can devote a few hours/days to help us out with this it would be greatly appreciated. Thank you. Hi, It would be easier to explain this if you play mafia wars (or any game that includes intra-game exchange of gifts/items between members) but the actual scripting doesn't require any knowledge of the game. Background Information Mafia Wars is a game on Facebook (and myspace, yahoo etc.) that among other things allows its players to send gifts to each other. Now because different people end up with more things of one type and are short of things of another type, the players have evolved a trading dynamic. Where x number of Item 1 is traded for y number of Item 2. A simple marketplace. And with this territory come scammers. Essentially a player who doesn't go through with his end of the deal. good player sends item to bad player. bad player removes good player from mafia and blocks him for ever contacting him through his facebook profile. This has given rise to my group, among many others, that lists these scammers (identified with their facebook profile ids) as they are reported every day. Now over time the list has grown and it has become difficult and unrealistic to expect people to know who is on the list and who is not. The Requirement A javascript bookmarklet (there are many already servicing different needs of the players) that sits on the browser and tells the user if the person he is about to trade with is a listed scammer or not. The Breakdown The user will click the bookmarklet when he is on the facebook profile of the person he is about to trade with. When clicked the script will pull the facebook profile id from the current page, and then scan a text file located on a third-party server and return with a pop-up box message that reports if the id is listed as a scammer or not. It should be pretty simple to do, except I don't know the first thing about javascript coding. So if there's anyone who can devote a few hours/days to help us out with this it would be greatly appreciated. Thank you |