I'd like a bookmarklet that takes info from my current url (like these):
https://www.themoviedb.org/tv/88396-falcon-winter-soldier
https://www.themoviedb.org/movie/64688-21-jump-street
https://www.themoviedb.org/person/7447-alec-baldwin
Extracts just id portion, the first set of numbers (88396, 64688, 7447, etc) and appends it to a new url like this:
https://webhookurl.com/webhook?movieID=(id from url)
Which opens in a background tab ideally.
I'm super new to javascript, been trying to cobble something together from similar answers on here but unable to figure it out. Any help is very much appreciated.
update: thanks to some help here with the regex and tinkering until i got the other tab thing to work, i now have a finished bookmarklet that works. thanks
ud2: changed again to 1. match urls with no '-film-name' after the id number, and also to open in a small new window rather than new tab so i can easily close after the webhook is accepted and it doesn't obstruct my view of the page
javascript:(function(){ open(window.location.toString().replace(/^https:\/\/www.themoviedb.org\/.*?\/([0-9]+)-?.*/, 'https://fakewebhook.com/webhook?movieID=$1'), "", "width=400, height=200");})()
You may use regex to form the new url from the given url.
'https://www.themoviedb.org/tv/88396-falcon-winter-soldier'.replace(/^https:\/\/www.themoviedb.org\/tv\/([0-9]+)-.+/, 'https://webhookurl.com/webhook?movieID=$1')
Related
So ostensibly I'm trying to make a button or a link who's target is contingent on the current page's URL. I'm working on a Wordpress portfolio site that opens up different projects in an Ajax window, but I also want to be able to link to the separate project page from that window. For instance, if I click the thumbnail for a project titled "Blue" it opens up the project in the ajax window and the url changes to "www.website.com/#blue." Incidentally, the url of the corresponding project page would then be "www.website.com/projects/blue". The idea is to hardcode the button into the Ajax window and write a script that generates the correct URL for the project page so my client doesn't have to copy-paste the code for the button and update the target URL every time she posts a project. This is what I came up with, but I'm not great with Jquery or Javascript and I think something might be wrong with my syntax or the structure of the script. Right now, nothing happens when I press the button.
First it splits the url at each "/" and creates an array from the different strings, then it removes the "#" from the unique string, and opens a new window with the new address.
EDIT There were some syntax errors, but it's still not working. Any thoughts on this new version:
$(".comment_button").click(function(){
var parse_url = window.location.href.split('/');
var project_name = parse_url[2].replace("#", "");
window.open("http://www.balletinform.com/projects/" + project_name);
});
Tried using a element ?, with target="_blank" attribute ?
<a id="blue" href="www.website.com/projects/blue" target="_blank">blue</a>
If I understand correctly, what you want to get is the #blue part of the url.
If so, you can use window.location.hash.
Your function will then looks like window.open("http://www.balletinform.com/projects/" + window.location.hash.substring(1));
Your current function was setting project_name to "www.balletinform.com" ([0]=>"http:"; splitted(/); [1]=>""; splitted('/'); [2]=>"www.balletinform.com"; splitted('/'); [3]=>"#blue").
So an alternative solution would have been var project_name = parse_url[parse_url.length-1].replace("#", "");
var new_url=""+(window.location.href).replace('#','projects/');
window.open(new_url);
Try replacing # with 'projects/'
I would like to make a Chrome extension that lets users send emails with certain text automatically filled in. I was using a mailto: link, but it cannot handle strings longer than 1024 characters, and it cannot create html links. Is there a way I can fill in additional text and maybe even HTML links, from within the email page (perhaps with local storage)?
Unfortunately there is no native chrome/javascript API to my knowledge. I did some searching and found an open source option that someone was working on but it was very skeleton. He was hoping others would jump on with him and flesh it out.
Sounds like you're trying this:
For creating the URL, you can use the &body= tag and url encode the message however there is a limit to the length. It sounds like you already figured out how to open a new tag using chrome so you've been able to create shorter emails using nothing but a modified URL string. I did something similar to that on my first chrome exension. It looked something like this.
function sendToUrl(){ chrome.tabs.query({active:true, windowId: chrome.windows.WINDOW_ID_CURRENT}, function(tab) {
//while this seems to generate the URL correctly, gmail limits how long the body text can be therefore this is not a viable solution
//Also there is no javascript API therefore there is no hope of sending an email.
//Need to loop through each tab and not just the first one
var currentTab = tab[0];
var tabInformation = RPATH.getTab(currentTab.id);
var mailUrl = "https://mail.google.com/mail/?view=cm&fs=1&tf=1&su=My%20Subject&to=";
// grab the email addresss from popup.html
mailUrl += document.getElementById("to").value + "&body=";
// get formBody from popup.html
var formBody = document.getElementById("body").value;
...
//I did some other stuff that isn't relevant here
...
//Concat final mailto url
mailUrl = mailUrl + formBody;
chrome.extension.sendMessage({mailUrl: mailUrl}, function(response){ console.log(response.farewell);});
});}
For longer email bodies
That only gets you half way though. The only alternative I could think of was to split up the tab open and filling out the email body. You could modify the email body after page load completes using append. That might look something like what I have below. Notice I'm selecting the iframe element, then finding the body tag inside of there, and finally appending some html just after the tag opens. Notice the email body is nothing more then html so div, tr, br, etc tags should all work in creating a well formatted email. In my previous example I pulled the text from the form as a string. You could instead use jquery to clone the html on your popup.html page and append the cloned html. For simplicity's sake, I only put text inside the append.
$("iframe#:1t4").find("body.editable").append('<p>My long email body</p>');
I suppose from there you could run a click event but you could also leave that to the user.
There is jquery modal box called fancybox and its pretty cool i like it and intend to use it for my site, but the problem is that my flash video is actually video player and videos passed to it like query e.g. player.swf?videosource=video1.flv and this modal does not work it show contents of flash file as if you open in in text editor.
Inside there's code
ajaxLoader = null, imgPreloader = new Image(), imgRegExp = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i, swfRegExp = /[^\.]\.(swf)\s*$/i,
I believe i need to modify this regex "/[^\.]\.(swf)\s*$/i" expression to somehow include what i have after swf can someone help me do it i going crazy nothing i tried works.
This regex should accept your player.swf?videosource=video1.flv query:
/[^\.]\.(swf)(?:\?.+)?\s*$/i
Here is what I would like to ideally do within my HTML - I would like to insert a bit of javascript that checks to see if a certain directory name is listed in the current user's URL and if so, output copy on the page. For example:
If the current URL has the word "trigger" in it such as:
http://www.mysite.com/pages/trigger/dosomestuff.html
then I want to output "confirmed" on the page.
I am not too familiar with javascript, so I am hoping that someone can help!
Thanks!
if (location.href.match("trigger"))
{
document.write("<h1>confirmed!</h1>")
}
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.
Just change window.location, e.g.
window.location=window.location.toString().replace(/^http:\/\/www\./,'https://admin.')
The full bookmarklet would then be:
javascript:(function() {window.location=window.location.toString().replace(/^http:\/\/www\./,'https://admin.');})()
For example you could replace a part of the string using the replace method with a regular expression.
javascript:location = location.href.replace(/http:/g, "https:" )
The above will assign the new string value to the location and trigger the page reload.
This one will change the site name
javascript:(function() {document.title=prompt("Enter Page Title");})();