Skip to content

Instantly share code, notes, and snippets.

@DEADB33F
Last active October 10, 2015 17:38
Show Gist options
  • Save DEADB33F/3727375 to your computer and use it in GitHub Desktop.
Save DEADB33F/3727375 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name reddit.com - F1 spoilers
// @namespace v1
// @include http://www.reddit.com/*
// @run-at document-start
// ==/UserScript==
function f1spoilers() {
var schedule = {
p1: [
'Fri 15 March 2013 01:30 GMT', //Austrailia
'Fri 22 March 2013 02:00 GMT', //Malaysia
'Fri 12 April 2013 03:00 GMT', //China
'Fri 19 April 2013 08:00 GMT', //Bahrain
'Fri 10 May 2013 09:00 GMT', //Spain
'Thu 23 May 2013 09:00 GMT', //Monaco
'Fri 07 June 2013 15:00 GMT', //Canada
'Fri 28 June 2013 10:00 GMT', //Britain
'Fri 05 July 2013 09:00 GMT', //Germany
'Fri 26 July 2013 09:00 GMT', //Hungary
'Fri 23 August 2013 09:00 GMT', //Belgium
'Fri 06 September 2013 09:00 GMT', //Italy
'Fri 20 September 2013 11:00 GMT', //Singapore
'Fri 04 October 2013 02:00 GMT', //S Korea
'Fri 11 October 2013 02:00 GMT', //Japan
'Fri 25 October 2013 05:30 GMT', //India
'Fri 01 November 2013 09:00 GMT', //Abu Dhabi
'Fri 15 November 2013 15:00 GMT', //USA
'Fri 22 November 2013 12:00 GMT' //Brazil
],
p2: [
'Fri 15 March 2013 05:30 GMT', //Austrailia
'Fri 22 March 2013 06:00 GMT', //Malaysia
'Fri 12 April 2013 07:00 GMT', //China
'Fri 19 April 2013 12:00 GMT', //Bahrain
'Fri 10 May 2013 13:00 GMT', //Spain
'Thu 23 May 2013 13:00 GMT', //Monaco
'Fri 07 June 2013 19:00 GMT', //Canada
'Fri 28 June 2013 14:00 GMT', //Britain
'Fri 05 July 2013 13:00 GMT', //Germany
'Fri 26 July 2013 13:00 GMT', //Hungary
'Fri 23 August 2013 13:00 GMT', //Belgium
'Fri 06 September 2013 13:00 GMT', //Italy
'Fri 20 September 2013 14:30 GMT', //Singapore
'Fri 04 October 2013 06:00 GMT', //S Korea
'Fri 11 October 2013 06:00 GMT', //Japan
'Fri 25 October 2013 09:30 GMT', //India
'Fri 01 November 2013 13:00 GMT', //Abu Dhabi
'Fri 15 November 2013 19:00 GMT', //USA
'Fri 22 November 2013 16:00 GMT' //Brazil
],
p3: [
'Sat 16 March 2013 03:00 GMT', //Austrailia
'Sat 23 March 2013 05:00 GMT', //Malaysia
'Sat 13 April 2013 04:00 GMT', //China
'Sat 20 April 2013 09:00 GMT', //Bahrain
'Sat 11 May 2013 10:00 GMT', //Spain
'Sat 25 May 2013 10:00 GMT', //Monaco
'Sat 08 June 2013 15:00 GMT', //Canada
'Sat 29 June 2013 10:00 GMT', //Britain
'Sat 06 July 2013 10:00 GMT', //Germany
'Sat 27 July 2013 10:00 GMT', //Hungary
'Sat 24 August 2013 10:00 GMT', //Belgium
'Sat 07 September 2013 10:00 GMT', //Italy
'Sat 21 September 2013 11:00 GMT', //Singapore
'Sat 05 October 2013 03:00 GMT', //S Korea
'Sat 12 October 2013 03:00 GMT', //Japan
'Sat 26 October 2013 06:30 GMT', //India
'Sat 02 November 2013 10:00 GMT', //Abu Dhabi
'Sat 16 November 2013 15:00 GMT', //USA
'Sat 23 November 2013 13:00 GMT' //Brazil
],
q: [
'Sat 16 March 2013 06:00 GMT', //Austrailia
'Sat 23 March 2013 08:00 GMT', //Malaysia
'Sat 13 April 2013 07:00 GMT', //China
'Sat 20 April 2013 12:00 GMT', //Bahrain
'Sat 11 May 2013 13:00 GMT', //Spain
'Sat 25 May 2013 13:00 GMT', //Monaco
'Sat 08 June 2013 18:00 GMT', //Canada
'Sat 29 June 2013 13:00 GMT', //Britain
'Sat 06 July 2013 13:00 GMT', //Germany
'Sat 27 July 2013 13:00 GMT', //Hungary
'Sat 24 August 2013 13:00 GMT', //Belgium
'Sat 07 September 2013 13:00 GMT', //Italy
'Sat 21 September 2013 14:00 GMT', //Singapore
'Sat 05 October 2013 06:00 GMT', //S Korea
'Sat 12 October 2013 06:00 GMT', //Japan
'Sat 26 October 2013 09:30 GMT', //India
'Sat 02 November 2013 13:00 GMT', //Abu Dhabi
'Sat 16 November 2013 18:00 GMT', //USA
'Sat 23 November 2013 16:00 GMT' //Brazil
],
r: [
'Sun 17 March 2013 06:00 GMT', //Austrailia
'Sun 24 March 2013 08:00 GMT', //Malaysia
'Sun 14 April 2013 08:00 GMT', //China
'Sun 21 April 2013 13:00 GMT', //Bahrain
'Sun 12 May 2013 13:00 GMT', //Spain
'Sun 26 May 2013 13:00 GMT', //Monaco
'Sun 09 June 2013 19:00 GMT', //Canada
'Sun 30 June 2013 13:00 GMT', //Britain
'Sun 07 July 2013 13:00 GMT', //Germany
'Sun 28 July 2013 13:00 GMT', //Hungary
'Sun 25 August 2013 13:00 GMT', //Belgium
'Sun 08 September 2013 13:00 GMT', //Italy
'Sun 22 September 2013 13:00 GMT', //Singapore
'Sun 06 October 2013 07:00 GMT', //S Korea
'Sun 13 October 2013 07:00 GMT', //Japan
'Sun 27 October 2013 09:30 GMT', //India
'Sun 03 November 2013 13:00 GMT', //Abu Dhabi
'Sun 17 November 2013 19:00 GMT', //USA
'Sun 24 November 2013 16:00 GMT' //Brazil
]
};
var type = localStorage.getItem('f1spoiler-type') || 'Mask',
match = localStorage.getItem('f1spoiler-match') || 'all',
period = localStorage.getItem('f1spoiler-period') || '1',
multiplier = localStorage.getItem('f1spoiler-multiplier') || '3600',
event = localStorage.getItem('f1spoiler-event') || 'r',
date = new Date(),
selector = '.thing.link'+( match == 'marked' ? '.linkflair-spoiler, .thing.over18, .thing:has(a.title:contains("spoiler")), .thing:has(a.title:contains("SPOILER")), .thing:has(a.title:contains("Spoiler"))' : '' );
for( d in schedule[ event ] ){
var date2 = new Date( schedule[ event ][ d ] ),
delta = date - date2,
delay = period * multiplier * 1000;
if( delta < 0 ) continue;
if( (delta - delay) < 0 ){
if( reddit.post_site == 'formula1' )
$( selector ).addClass('spoiler'+type );
else
$('.subreddit[href="http://www.reddit.com/r/formula1/"]').parents( selector ).addClass('spoiler'+type );
}
break;
}
// Add menu
if( reddit.post_site != 'formula1' ) return;
$('.side').append('\
<div class="spacer">\
<div class="sidecontentbox collapsible" id="f1-spoilers">\
<div class="title">\
<h1>F1 SPOILER SETTINGS</h1>\
<span class="collapse-button">-</span>\
</div>\
<ul class="content" style="display: block; ">\
<li>\
<select id="type"><option>Mask</option><option>Hide</option></select>\
<select id="match"><option value="all">all links</option><option value="marked">links marked as spoilers</option></select> for\
<select id="period"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>6</option><option>7</option><option>8</option><option>9</option><option>10</option><option>12</option><option>13</option><option>14</option><option>15</option><option>16</option><option>17</option><option>18</option><option>19</option><option>20</option><option>21</option><option>22</option><option>23</option></select>\
<select id="multiplier"><option value="3600">hour(s)</option><option value="86400">day(s)</option></select> after \
<select id="event"><option value="q">qualifying</option><option value="r">the race</option><option value="p1">practice 1</option><option value="p2">practice 2</option><option value="p3">practice 3</option></select> starts. \
</li>\
</ul>\
<script>r.ui.collapsibleSideBox("f1-spoilers")</script>\
</div>\
</div>');
$('#f1-spoilers select')
.val( function(){ return localStorage.getItem( 'f1spoiler-'+ this.id ) } )
.change( function(){ localStorage.setItem( 'f1spoiler-'+ this.id, this.value ) } );
}
// Add script to the page
document.addEventListener('DOMContentLoaded',function(e){var s=document.createElement('script');s.textContent="("+f1spoilers.toString()+')();';document.head.appendChild(s)});
// Add CSS
(function addcss(){
if( !document.head ) return setTimeout( addcss );
var css = '\
.thing.spoilerHide, .thing.spoilerMask .nsfw-stamp{ display:none }\
.thing.spoilerMask .buttons:before{ content:"SPOILER"; color: #396C39; font-size: x-small; text-decoration: none; padding: 0 2px; border: 1px solid #79B279 !important; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px }\
.thing.spoilerMask a.title{ background-color:black; color:black!important;text-shadow: none }\
.thing.spoilerMask a.title:hover{ background-color:inherit; color:blue!important }\
.thing.spoilerMask a.title.click:hover, .thing.spoilerMask a.title:visited:hover{ color:#551A8B!important }\
.thing.spoilerMask .thumbnail img{ padding-left:70px!important; background-color:black }\
.thing.spoilerMask .thumbnail img:hover{ padding-left:0!important }\
#f1-spoilers input{ display:inline;width:auto }';
s=document.createElement('style');s.type="text/css";s.textContent=css;document.head.appendChild(s);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment