/    Sign up×
Community /Pin to ProfileBookmark

How do I modify a url?

I have to apologize first off, I’m very new to coding. I want to be able to do the following automatically by clicking a button or something like that:

1: Grab current url

2: Strip url of prefix & .html (example):
[url]http://Dommy2Hotty.com/videos/video1.html[/url]
becomes
video1

3: Add my own prefix and .wmv (example):
[url]http://Dommy2Hotty.com/MEDIA/video1.wmv[/url]

4: Save that wmv to my hard drive.

Is this possible? Thank you in advance.

Dominic

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@ShampieJan 29.2008 — Hey Dommy

[CODE]1: Grab current url[/CODE]
var docurl = document.location.toString();

[CODE]2: Strip url of prefix & .html (example):
http://Dommy2Hotty.com/videos/video1.html
becomes
video1[/CODE]

var voos = docurl.split("/");

var str = voos[voos.length-1];

var solution = str.split(".");

alert(solution[0]); //this will give you everything between the last '/' and the .html

[CODE]3: Add my own prefix and .wmv (example):
http://Dommy2Hotty.com/MEDIA/video1.wmv[/CODE]

window.location.replace("http://Dommy2Hotty.com/MEDIA/"+solution[0]+".wmf")

[CODE]4: Save that wmv to my hard drive.[/CODE]
assuming you are not a pirate and know your copy rights you may have to use save file as, since I am not sure you can actually do this part with javascript.

Be aware that some sites will give you the finger for trying to get data this way such as the site you presented.

Good luck.
Copy linkTweet thisAlerts:
@magentaplacentaJan 29.2008 — Save the following as a [b].html[/b] file on your local system. Open it in a browser and click the buttons from the top to the bottom.

[CODE]<script type="text/javascript">
function getURL() {
var currentURL = location.href;
var current = document.getElementById("current");
current.style.display = "block";
current.innerHTML = currentURL;
}

function getPath() {
var pathName = location.pathname;
var path = document.getElementById("path");
path.style.display = "block";
path.innerHTML = pathName;
}

function extractLast() {
var pathName = location.pathname;

//find last "/"
var last = pathName.lastIndexOf("/");

//move forward one character
var start = last + 1;

//extract value
var end = pathName.substring(start);

var lastitem = document.getElementById("lastitem");
lastitem.style.display = "block";
lastitem.innerHTML = "<b>Last item:</b> " + end;


var myurl = document.getElementById("myurl");
myurl.style.display = "block";
myurl.innerHTML = "<b>Hijacked URL:</b> http://Dommy2Hotty.com/MEDIA/" + end.replace(".html", ".wmv");
}

</script>

<input type="button" onclick="getURL();" value="Get current url">
<div id="current" style="display:none; padding:4px;"></div>

<p>
<input type="button" onclick="getPath();" value="Get path">
<div id="path" style="display:none; padding:4px;"></div>

<p>
<input type="button" onclick="extractLast();" value="Extract last item and hijack">
<div id="lastitem" style="display:none; padding:4px;"></div>
<div id="myurl" style="display:none; padding:4px; background:#efefef"></div>[/CODE]
Copy linkTweet thisAlerts:
@Dommy2HottyauthorJan 29.2008 — I truly appreciate the help. I'm trying to teach myself, but sometimes a little help is needed. Basically, there is a site I go to daily for new videos that does not provide a download link. I checked the source code, found the file name of the video, and modified the url manually. It's nothing copyrighted, basically your run of the mill kids doing dumb stuff, people getting tasered, exercise ball to the face type videos.
Copy linkTweet thisAlerts:
@Dommy2HottyauthorFeb 01.2008 — Save the following as a [b].html[/b] file on your local system. Open it in a browser and click the buttons from the top to the bottom.

[CODE]<script type="text/javascript">
function getURL() {
var currentURL = location.href;
var current = document.getElementById("current");
current.style.display = "block";
current.innerHTML = currentURL;
}

function getPath() {
var pathName = location.pathname;
var path = document.getElementById("path");
path.style.display = "block";
path.innerHTML = pathName;
}

function extractLast() {
var pathName = location.pathname;

//find last "/"
var last = pathName.lastIndexOf("/");

//move forward one character
var start = last + 1;

//extract value
var end = pathName.substring(start);

var lastitem = document.getElementById("lastitem");
lastitem.style.display = "block";
lastitem.innerHTML = "<b>Last item:</b> " + end;


var myurl = document.getElementById("myurl");
myurl.style.display = "block";
myurl.innerHTML = "<b>Hijacked URL:</b> http://Dommy2Hotty.com/MEDIA/" + end.replace(".html", ".wmv");
}

</script>

<input type="button" onclick="getURL();" value="Get current url">
<div id="current" style="display:none; padding:4px;"></div>

<p>
<input type="button" onclick="getPath();" value="Get path">
<div id="path" style="display:none; padding:4px;"></div>

<p>
<input type="button" onclick="extractLast();" value="Extract last item and hijack">
<div id="lastitem" style="display:none; padding:4px;"></div>
<div id="myurl" style="display:none; padding:4px; background:#efefef"></div>[/CODE]
[/QUOTE]


Works perfectly! My only other question is how to load that code into another page that's online?
×

Success!

Help @Dommy2Hotty spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...