Youtube Popup

上班偷看Youtube的小工具XD
可把Youtube變成彈出視窗
http://i.imgur.com/W9AcEJI.png

view raw 1-read.md hosted with ❤ by GitHub
var css = document.createElement('style');
css.type = 'text/css';
css.innerHTML = ".myPopup{box-shadow:inset 0 1px 0 0 #fff;background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#ededed),color-stop(1,#dfdfdf));background:-moz-linear-gradient(center top,#ededed 5%,#dfdfdf 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed',endColorstr='#dfdfdf');background-color:#ededed;border-radius:10px 10px 0 0;text-indent:0;border:1px solid #dcdcdc;display:block;color:#777;cursor:pointer;font-family:arial;font-size:14px;font-weight:700;font-style:normal;height:24px;line-height:24px;width:62px;text-decoration:none;text-align:center;text-shadow:1px 1px 0 #fff}.myPopup:hover{background:-webkit-gradient(linear,left top,left bottom,color-stop(0.05,#dfdfdf),color-stop(1,#ededed));background:-moz-linear-gradient(center top,#dfdfdf 5%,#ededed 100%);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf',endColorstr='#ededed');background-color:#dfdfdf}.myPopup:active{position:relative;top:1px}";
document.head.appendChild(css);
var body = document.getElementsByTagName('body')[0];
var ifms = document.querySelectorAll('iframe[src^="http://www.youtube.com/embed/"],iframe[src^="http://www.youtube.com/embed/"]');
for (var i = 0, max = ifms.length; i < max; i++) {
var pNode = ifms[i].parentNode;
var btn = document.createElement('a');
btn.className = 'myPopup';
btn.innerHTML = 'Popup';
pNode.insertBefore(btn, ifms[i]);
var vid = ifms[i].src.replace(/http(s)?:\/\/www\.youtube\.com\/embed\//, '');
(function(btn, vid) {
btn.addEventListener('click', function() {
window.open('https://youtube.googleapis.com/v/' + vid, (new Date).getTime(), "width=328,height=206,top=0,left=0");
});
})(btn, vid);
}
view raw 2-popup.js hosted with ❤ by GitHub

goo.gl

$.ajax({
url: 'https://www.googleapis.com/urlshortener/v1/url?key=YOUR_API_KEY_PUT_HERE',
type: 'POST',
data: JSON.stringify({
longUrl: 'http://www.playpcesor.com/2015/05/office-2016-google-drive.html'
}),
contentType: 'application/json',
dataType: 'json',
success: function(result, status, xhr) {
console.log(result.id);
}
});
view raw jq.js hosted with ❤ by GitHub
var request = require("request");
request({
method: 'POST',
url: 'https://www.googleapis.com/urlshortener/v1/url?key=YOUR_API_KEY_PUT_HERE',
body: {
longUrl: 'http://www.playpcesor.com/2015/05/office-2016-google-drive.html'
},
json: true
}, function(error, response, body) {
if (error) {
console.log(error);
} else {
console.log(body.id);
}
});
view raw node.js hosted with ❤ by GitHub
var api_url = 'https://www.googleapis.com/urlshortener/v1/url?key=YOUR_API_KEY_PUT_HERE';
var request = new XMLHttpRequest();
request.open('POST', api_url, true);
request.setRequestHeader('Content-Type', 'application/json');
request.setRequestHeader('Accept', 'application/json');
request.onload = function() {
var rep_json = JSON.parse(request.responseText);
if (rep_json.id) {
prompt('goo.gl', rep_json.id);
} else {
alert(rep_json.error.message);
}
};
request.onerror = function() {
alert('Shorten url fail, network error.');
};
request.send('{"longUrl":"' + location.href + '"}');
view raw purejs.js hosted with ❤ by GitHub

node.js request get 302 location

var request = require("request");
request({
method: 'GET',
url: 'http://goo.gl/UgTWRZ',
followRedirect: false
}, function(error, response, body) {
if (error) {
console.log(response.statusCode);
} else {
console.log(response.headers.location);
}
});
view raw 302.js hosted with ❤ by GitHub