Greasy Fork

Greasy Fork is available in English.

TVMaze: add "Watched" button to calendar

Add "Mark as watched" button to calendar entries at TVMaze

当前为 2018-10-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        TVMaze: add "Watched" button to calendar
// @description Add "Mark as watched" button to calendar entries at TVMaze
// @namespace   BlackNullerNS
// @include     http*://www.tvmaze.com/calendar*
// @version     1.2
// ==/UserScript==

var btn = document.createElement('button');
btn.innerHTML = '✓';
btn.style.fontWeight = 'bold';
btn.style.border = 0;
btn.style.padding = '2px 4px';
btn.style.background = 'transparent';
btn.style.color = '#3C948B';
btn.style.cursor = 'pointer';
btn.setAttribute('title', 'Mark as watched');

var handler = function (e) {
    e.preventDefault();

    var self = this,
        entry = this.parentNode.parentNode,
        link = entry.querySelector('a[href*="episodes/"]');

    if (!link) {
        return false;
    }

    var eid = link.getAttribute('href').split('episodes/')[1].split('/')[0];
    var url = '/watch/set?episode_id=' + eid;
    var csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content');

    var xhr = new XMLHttpRequest();
    xhr.open('POST', url);
    xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
    xhr.setRequestHeader('X-CSRF-Token', csrf);

    xhr.addEventListener('load', function () {
        entry.classList.add('watched');
        self.remove();
    });

    xhr.send("type=0");
};

var mouseover = function () {
    this.style.color = '#cc0000';
};

var mouseout = function () {
    this.style.color = '#3C948B';
};

var cloned;
var episodes = document.querySelectorAll(".entry:not(.watched)");

for (var i = 0, l = episodes.length; i < l; i++) {
    cloned = btn.cloneNode(true);
    cloned.addEventListener('click', handler);
    cloned.addEventListener('mouseover', mouseover);
    cloned.addEventListener('mouseout', mouseout);

    episodes.item(i).firstElementChild.appendChild(cloned);
}