YouTube channel name log

Logs names of YouTube channels of watched videos in history to allow searching browsing history by channel owner.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         YouTube channel name log
// @description  Logs names of YouTube channels of watched videos in history to allow searching browsing history by channel owner.
// @namespace    gercomsci
// @version      1.0 beta
// @author       Gercomsci
// @run-at       document-end
// @grant        none
//
// @match        *://youtube.com/watch?v=* 
// @match        *://*.youtube.com/watch?v=* 
// ==/UserScript==
 
/* Code based on https://greasyfork.org/de/scripts/427543-soundcloudlog */

// == Main code ==
 
//  Function to locate relative video URL
var channelName;
function updateChannelName() { 
    channelName = document.getElementsByClassName("slim-owner-icon-and-title")[0].getAttribute("aria-label");
    logChannelName(); 
}
 
function updateDate() {
    timestamp = new Date().toISOString(); 
    // Very practical! https://stackoverflow.com/questions/2573521/how-do-i-output-an-iso-8601-formatted-string-in-javascript/8563517#8563517
}
 
function hasVideoChanged() {
    updateDate();
    if  ( channelName !== document.getElementsByClassName("slim-owner-icon-and-title")[0].getAttribute("aria-label")) {
        updateChannelName(); // read new video URL
        logChannelName();    // record it to browsing history 
        console.log('YouTube channel name log '+timestamp+': Channel name changed to '+channelName); // for debugging
    } 
  else { (0); } // Placeholder, in case necessary later.
}
 
function logChannelName() { 
        window.location.href = ("#YouTube_channel_name_log-"+timestamp+":"+channelName);
        if (navigator.userAgent.indexOf("Chrome") == -1) { // do not do this on Chromium-based browsers, as it navigates back from the non-anchored state
            javascript:history.go(-1); // Remove anchor after logging, to prevent navigation interference.
               };
        window.history.pushState('page2','Title',window.location.toString().split("#")[0]); // remove anchor to clear the URL
}
 
// Check for change every second. If change detected, apply to URL.
changeCheck = setInterval(function() { hasVideoChanged() }, 1000);