-
-
Save NKid/ade798cc13c9992ffb21 to your computer and use it in GitHub Desktop.
goo.gl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript: (function() { | |
var l = location, | |
tmp_url = l.href, | |
msg = document.createElement('div'); | |
if(l.href.indexOf('utm_source') != -1) { | |
tmp_url = l.href.replace(/(\?|&)utm_source.*/i, ''); | |
} else if((l.href.indexOf('youtube.com') != -1) && /(v=.{11})/.test(l.search)) { | |
tmp_url = 'http://www.youtube.com/watch' + l.search.replace(/.*(v=.{11}).*/i, '?$1'); | |
} else if(l.href.indexOf('www.mobile01.com/gallerydetail.php') != -1) { | |
tmp_url = l.href.replace(/&fp=(\d{1})/, ''); | |
} else if(l.href.indexOf('mobile01.com') != -1) { | |
tmp_url = l.href.replace(/&last=\d+/, ''); | |
} | |
var api_url = 'https://www.googleapis.com/urlshortener/v1/url'; | |
var request = new XMLHttpRequest(); | |
request.open('POST', api_url, true); | |
request.setRequestHeader('Content-Type', 'application/json'); | |
request.onload = function() { | |
var response_json = JSON.parse(request.responseText); | |
if(response_json.id) { | |
msg.style.display = 'none'; | |
prompt('goo.gl', response_json.id); | |
} else alert("Shorten%20url%20fail,%20goo.gl%20return%20error."); | |
}; | |
request.onerror = function() { | |
alert("Shorten%20url%20fail,%20network%20error."); | |
}; | |
msg.style.position = 'fixed'; | |
msg.style.height = '30'; | |
msg.style.width = '200'; | |
msg.style.margin = '5px'; | |
msg.style.top = '0'; | |
msg.style.left = '0'; | |
msg.style.padding = '5px'; | |
msg.style.backgroundColor = '#F99'; | |
msg.style.color = '#000'; | |
msg.style.borderRadius = '5px'; | |
msg.style.zIndex = 999; | |
msg.innerHTML = 'Shorten%20current%20url...'; | |
var b = document.getElementsByTagName('body')[0]; | |
b.appendChild(msg); | |
request.send('{"longUrl":"' + tmp_url + '"}'); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment