Created
April 1, 2023 08:45
-
-
Save Maartyl/31fb33a5405cc26756b6a8c6258aa42b to your computer and use it in GitHub Desktop.
Copy Meta about current YT Video
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name YT Copy Meta | |
// @namespace https://github.com/Maartyl | |
// @version 0.1 | |
// @description Copy Meta about current Video | |
// @author Maartyl | |
// @match https://www.youtube.com/watch* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com | |
// @grant GM_setClipboard | |
// @run-at context-menu | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function gattr(qry, attr){ | |
attr = (attr==null)?'content':attr; | |
return document.querySelector(qry).getAttribute(attr); | |
} | |
function mp(name, attr){ | |
return gattr("meta[property='"+name+"']", attr); | |
} | |
function grab(){ | |
let title = mp("og:title"); | |
let url = mp("og:url"); | |
let image = mp("og:image"); | |
let kwds = gattr("meta[name=keywords]"); | |
let chUrl = gattr("#channel-name [href]", "href"); | |
let chName = document.querySelector("#channel-name [href]").innerText; | |
// assumes RMB on comment-time-ref | |
let cmnt = document.activeElement.href | |
let built = cmnt == null ? "" : "[[YT cmnt]]"; | |
if (cmnt){ | |
built += "\nytCmnt:: " + cmnt; | |
} | |
built += "\nytUrl:: " + url; | |
built += "\nytTitle:: " + title; | |
built += "\nchName:: " + chName; | |
built += "\nchUrl:: " + chUrl; | |
built += "\n![thumbnail]("+image+")"; | |
built += "\nytKeywords:: " + kwds; | |
built += "\n"; | |
GM_setClipboard(built); | |
} | |
grab(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment