Skip to content

Instantly share code, notes, and snippets.

@kejun
Created January 20, 2012 06:48
Show Gist options
  • Save kejun/1645817 to your computer and use it in GitHub Desktop.
Save kejun/1645817 to your computer and use it in GitHub Desktop.
FM单曲循环(纯属个人瞎玩, 要求Firefox4+)
// ==UserScript==
// @name RepeatFM
// @namespace org.kejun
// @description FM单曲循环(纯属个人瞎玩, 要求Firefox4+)
// @include http://douban.fm, http://douban.fm/*
// ==/UserScript==
var isRepeat = localStorage.getItem('is_repeat_fm')|0;
function importCSS(str) {
var css = document.createElement('style');
css.type = 'text/css';
document.getElementsByTagName('head')[0].appendChild(css);
if (css.styleSheet) {
css.styleSheet.cssText = str;
} else {
css.appendChild(document.createTextNode(str));
}
}
function init() {
importCSS([
'.repeat-favsong-button { position:absolute;right:40px;bottom:100px;width:100px;height:100px;opacity:0.2;border-radius:20px;cursor:pointer;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFcAAABMCAYAAAAY2Ss0AAAIUUlEQVR42u3dfUib5xrH8RKCBBEpoRQZRUSkjCIi4zAOMkYpUqR/HMYoo0g5yKHIKFKKFDqkCGU43/JizIvGxNeYyjicPw5yOBQpoUgpIkNkFBlSRKRIKUFKEAkhXPsqugfPPDG5nzzJE+0fn12XId73df0mwtNVd+Hx48clIRqds0efPWuIPptrob9LbccTdPN6dzSKZ3Nd1DbqbdzAFdiKNbOpAyWYOnTgZyxhDVuEG6cmCDJNsEJ/JI0dXn/Pezbpf0EMHrTAfi7DJRALLuMLDGINaciRWa2q9gks4A4fX6OWn/lwWbQKbfgn3kEMlsKv8OI6bGcu3NnZaDlaEUMcUgQbmEbjmQg3EolWssxXWI5oS0rmXhMxqIeXvgHWkgyXBarhxHZkdlaoQOa+QGbT1JVIZLaTWlZS4TJ0PV5jD2JiCYRQbfpwGbIS97ANho+AmmM/Ayo1Uqh+BS2wmDLcmZlIGfqxDSlBm/gOVvOEqwXbhT1ICdvAP2AzRbjTMzOX4MYe5MA01HsUtU9Se6iWoofLIG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FP0W9R56rEHg3Mdrk4p/AYPod7EwbeAT+H29cWgBZVjj3m0oxF/hPopXPT39j1CEnKCJHbwHm+xikX0DvT2fUvIlZ/+DycZw+21E1YnuvEU3VrP6z/1/p36LZpQ2/9Tn60Yc/4OghfqIYxxb2QAAAAASUVORK5CYII=) no-repeat center center; }',
'.repeat-favsong-button:hover,',
'.repeat-favsong-button.active { opacity:.6;background-color:#ddd; }'
].join(''));
var button = document.createElement('div');
button.className = isRepeat? 'repeat-favsong-button active' : 'repeat-favsong-button';
button.addEventListener('click', function(){
if (this.className.indexOf('active') > 0) {
this.title = '单曲循环关闭';
isRepeat = 0;
} else {
this.title = '单曲循环开启';
isRepeat = 1;
}
this.classList.toggle('active');
localStorage.setItem('is_repeat_fm', isRepeat);
} , false);
document.body.appendChild(button);
var oldHandler;
var wait = setTimeout(function(){
if (typeof unsafeWindow.extStatusHandler === 'undefined') {
wait = setTimeout(arguments.callee, 100);
return;
}
clearTimeout(wait);
unsafeWindow.old_extStatusHandler = unsafeWindow.extStatusHandler;
unsafeWindow.extStatusHandler = function(o) {
var song = eval('(' + o + ')'),
actions = {
'e': function() {
if (isRepeat) {
self.location.href = unsafeWindow.FM.getCurrentSongInfo().url;
}
}
};
actions[song.type] && actions[song.type]();
unsafeWindow.old_extStatusHandler(o);
};
}, 100);
}
init();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment