Control how many past weeks you want to see and many other enhancements
当前为
// ==UserScript==
// @name Airdates.tv show past weeks
// @namespace V@no
// @description Control how many past weeks you want to see and many other enhancements
// @include http://www.airdates.tv/*
// @include https://www.airdates.tv/*
// @version 1.6.2
// @noframes
// @grant none
// ==/UserScript==
//tab = 2 spaces
// hide all past days
var d = new Date(),
today = $("div.day[data-date='" + d.getFullYear() + ("00" + (d.getMonth() + 1)).slice (-2) + ("00" + d.getDate()).slice (-2) + "']"),
stop = false;
$("div.days").children().each(function(i, o)
{
if ($(this).is(today))
{
$(this).attr("today", "true");
stop = true;
}
if (!stop)
{
$(this).addClass("past");
}
});
let week = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"],
daysNum = week.indexOf($(today).find(".date").text().toLowerCase().match(/([^,]{3})/)[1]);
//there is no identication of which week a day belong to, so we must make sure that previous days of current week don't count as previous week.
if (daysNum > 0)
{
for(var i = 0, prev = today.prev(); i < daysNum && prev; i++)
{
prev.removeClass("past");
prev = prev.prev();
}
}
var daysPast = $('div.past'),
weeks = parseInt(readCookieRaw("w")),
weeksMax = Math.round((daysPast.length) / 7);//how many past weeks do we have available?
if (isNaN(weeks))
weeks = readCookieRaw("p") == "1" ? weeksMax : 0;
if (weeks > weeksMax)
weeks = weeksMax;
//main function that shows/hides past days
function showWeeks()
{
//get week numbers from dropdown
var weeks = parseInt($("#pastWeeks").val());
//just some sanity check
if (weeks * 7 > daysPast.length)
weeks = weeksMax;
if (weeks < 1)
weeks = 0;
for(var i = weeksMax; i > 0; i--)
$( "div.calendar" ).toggleClass("showPast" + i, (weeks >= i));
createCookie("w", weeks);
}
//add new class pastNN to each past day, where NN is a week number.
daysPast.each(function(i)
{
$(this).addClass("past" + (Math.ceil((daysPast.length - i) / 7 % (weeksMax + 1))));
});
//create dropdown menu with number of available past weeks
var dropdown = document.createElement("select");
dropdown.id = "pastWeeks";
for(var i = 0; i <= weeksMax; i++)
{
var option = document.createElement("option");
option.value = i;
option.text = i;
option.selected = (weeks == i);
dropdown.appendChild(option);
}
//add event listener to dropdown
$(dropdown).change(showWeeks);
var span = document.createElement("span");
span.id = "past-weeks";
span.appendChild(document.createTextNode("Show past weeks:"));
span.appendChild(dropdown);
//insert our dropdown and new text into document
$(".calendar").prepend(span);
//hide "Show/Hide past month" links
$("#past-showing").toggle(true);
togglePast();//make sure we disable "Show past month"
$("#past-showing").toggle(false);
$("#past-hidden").toggle(false);
showWeeks();
var prevOpened = null;
//adding attribute "opened" to the entry allows us show/hide things from CSS based on entry state
$("div.days").on("click", "div.entry div.title", function()
{
if (prevOpened)
{
prevOpened.attr("opened", "");
let po = prevOpened;
setTimeout(function()
{
po.removeAttr("opened");
}, 200);
prevOpened = null;
}
let $entry = $( this ).parent();
if ($entry.attr("opened") === undefined)
{
$entry.attr("opened", "");
//idealy this should've been done via "on complete" function submitted for slideUp/slideDown
setTimeout(function()
{
$entry.attr("opened", "1");
}, 300);
prevOpened = $entry;
}
});
//create stylesheet. A little trick to have multi-line text in javascript
var style = document.createElement("style"),
css = function(){/*
div.showPast1 div.past1,
div.showPast2 div.past2,
div.showPast3 div.past3,
div.showPast4 div.past4,
div.showPast5 div.past5,
div.showPast6 div.past6,
div.showPast7 div.past7,
div.showPast8 div.past8,
div.showPast9 div.past9
{
display: block;
}
div.calendar.searching > span
{
text-decoration: line-through;
}
#pastWeeks
{
margin-left: 0.5em;
}
/* color picker icon that works on dark background *//*
.picker
{
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsSAAALEgHS3X78AAAA70lEQVQoz42SIU4DQRhG378hWYerq1uHQtYhSOpwq5AoOAGOOxBO0DugSE9QQ2pIEQ2mFkRdg3gI/m2WdifhSyaTzMzLfPMyQSFqDZwCDXCW8w54A16LkNqorTpTPwF/t5yrbQkcJTTvgP5QH6pCxQa4iojLwkvqagAaAxfAdaHNF7CuBqApcBsRJ+oQ+5yC/si4U1f5jn0Oxaijf0Hqd9pt82zdN7goQB/qvTrJs3VXc6LOCtAqmzR7IFOlkPP+YkSgvgOPwAuwiYjdod6b7raehEXppj44VZ8SWB5JKCTUJn/KGNgCG2ANbI/q9fIDBeUkvmW0dr0AAAAASUVORK5CYII=');
background-repeat: no-repeat;
width: 14px;
height: 14px;
}
.picker-light
{
background-image: none;
width: 12px;
height: 12px;
}
.picker-light:hover
{
background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAAMCAYAAABWdVznAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QAAAAAAAD5Q7t/AAAACXBIWXMAAAsSAAALEgHS3X78AAAA10lEQVQoz22RIU8DQRBG31wuOYerqzuHwqARJHW4U5Uo+BP8CQwWwx8AWYOtaTB1TRDYIs41IXkIpmRZ7ks2K/bN7pudoIraASdAD5zmfgC2wOYfrPbqoD6qe8CfI1fqUBfMEl4dwXKpd02l0gNXEXHJdLqmgOfABbCcItVPYNcU8AK4iYhWnap5Abal9zo9f1M3rM7awvu8vDkiUL+AJ+A5v3RsU+esfDvhd+ABeAV2wBgRB9Tro0qhsFZvcyZd3f1CvU/wLQc2TMJAqH32MQdG4OOPQpVv7by2BF48XOUAAAAASUVORK5CYII=');
}
/* today column border *//*
div.today
{
border-color: #FFC800;
}
/* higlighted title under cursor *//*
div.title:hover
{
background-color: #ffffd5;
}
div[white] div.title:hover
{
color: black;
}
/* highlight opened entry *//*
.entry[opened]
{
border: 1px solid black;
}
.entry[opened][white]
{
border-color: grey;
}
div[opened] + div
{
border-top: 0;
}
/* cross out white color *//*
/* only show when entry opening animation is complete *//*
div[opened="1"] .color.none::before,
div[opened="1"] .color.none::after
{
background-color: red;
position: absolute;
display: block;
content: "";
width: 10px;
height: 2px;
border-radius: 2px;
margin: 4px 0 0 0;
}
.color.none::before
{
transform: rotate(-45deg);
}
.color.none::after
{
transform: rotate(45deg);
}
/* change border color on color selectors on dark backgrounds *//*
.entry[white] .color
{
border-color: white;
}
/* set font color on dark backgrounds *//*
.entry[white]
{
color: white;
}
#colorPickerHolder,
#colorPickerHolderNew
{
display: initial !important;
}
*/};
style.innerHTML = css.toString().slice(14, -3).replace(/\*\/\/\*/g, "*/");
$("head").append(style);
//fix for search input field doesn't show "x" after page refresh and it's not empty
(function(s)
{
if (s.val())
s.addClass('x');
else
s.removeClass('x');
})($("#searchBecauseNoOneChecks"));
//fix inability remove a show when "Important stuff only" is active
window.assignColor = function ( seriesId, color, permanent ){
//$( "div.entry[data-" + attr + "='" + value + "']" )entries( "series-id", seriesId ).css( "background-color", color?color:"" );
$("#css_"+seriesId).remove();
var curShow = $(".activeOnly").find(".entry[data-series-id='" + seriesId + "']").removeAttr("style");
var origColor = color;
color = color||"#FFF";
var col = new Colors().setColor(color);
var hover = typeof(permanent) == "undefined";
if (hover)
{
$(".entry[data-series-id='" + seriesId + "']").find(".details[style='display: block;']").parent().attr("id", "temp" + seriesId);
}
if( col.HEX != "FFFFFF" || hover)
{
var style =
"<style id='css_I'>\
.entry[data-series-id='I'], li[data-series-id='I'] .color{background-color:C;}\
.activeOnly .entry[data-series-id='I']{ display: block !important; }\
</style>"
.replace( /I/g, seriesId )
.replace( /C/g, color )
;
$(style).appendTo("body");
//hide entries when cursor over "no color"
curShow.each(function(i, o)
{
o.style.visibility = col.HEX == "FFFFFF" && hover && $(this).attr("opened") === undefined ? "hidden" : "";
});
}
//adding attribute "white" to the entry allows us change color for font/border on dark backgrounds within CSS
if (col.rgbaMixBlack.luminance < 0.23)
$(".entry[data-series-id='" + seriesId + "']").attr("white", "");
else
$(".entry[data-series-id='" + seriesId + "']").removeAttr("white");
if( permanent ){
DB.setColor( seriesId, origColor );
}
};
//fix incorrect initial color in colorpicker
//fix clicking outside of colorpicker saves selected color instead of discarding
//fix close colorpicker by pressing escape button
var editingSeriesId = -1;
var clone = $("#colorPickerHolder").clone();
$("#colorPickerHolder").remove();
var picker = clone.colorPicker(
{
animationSpeed: 0,
opacity: false,
buildCallback: function($elm)
{
let cp = this;
$elm
.append('<div class="cp-disp"><input type="button" value="save"> <input type="button" value="cancel"></div>')
.on( "click", 'input', function()
{
if (this.value == 'save')
assignColor( editingSeriesId, "#" + cp.color.colors.HEX, true );
editingSeriesId = -1;
cp.toggle();
});
$("body").on("keydown", $elm, function(e)
{
//ESC(27) = cancel
if (e.which == 27)
cp.toggle();
});
},
cssAddon: ".cp-disp{ padding-bottom: 2px; clear:both; }",
renderCallback: function($elm, toggled) {
var colors = this.color.colors;
// on show
if( toggled === true ){
if( editingSeriesId > 0 )
{
//set initial color in colorpicker based on current entry or default to white
this.color.setColor(DB.getColor(editingSeriesId) || "#FFFFFF");
this.render();
}
}
// on change
else if( toggled === undefined ){
//preview new color
assignColor( editingSeriesId, "#" + colors.HEX, false );
}
// on hide
else if( toggled === false ){
//restore entry color
if( editingSeriesId > 0 )
loadColor( editingSeriesId );
editingSeriesId = -1;
picker.detach().appendTo("body");
}
}
}).attr("id", "colorPickerHolderNew"); //replace ID so it won't initialize in main.js
//disable any other click event handlers
$("body").off("click", ".picker");
// now hook up the picker to the picker icons
$("body").on("click", ".picker", function(e){
if( !$(e.target).hasClass("picker") ) return;
editingSeriesId = $(this).parents("[data-series-id]").data("series-id");
picker.detach().appendTo(this).click();
});
//fix new selected color doesn't show for logged in users when clicked quick color square move quickly moved cursor away from it
DB.setColor = function( seriesId, color ){
if( DB.username ){
let oldColor = DB.savedColors[seriesId];
if(color) DB.savedColors[seriesId] = color;
else delete DB.savedColors[seriesId];
$.post( "/_u/setColor", {username: DB.username, seriesId:seriesId, color:color} )
.error(function(e,e2){
if(oldColor) DB.savedColors[seriesId] = oldColor;
else delete DB.savedColors[seriesId];
alert( "no permission? no internet? anyways, color was not saved. " );
assignColor( seriesId, DB.getColor(seriesId), false );
} );
}
else{
if(color) DB.savedColors[seriesId] = color;
else delete DB.savedColors[seriesId];
if( color ) createCookie( "ad_" + seriesId, color );
else eraseCookie( "ad_" + seriesId );
}
};
//make sure new assignColor was used for each show
for(let i in DB.savedColors)
{
assignColor(i, DB.savedColors[i], false);
}