YouTube channel name log

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);