Rename directories for better organization

This commit is contained in:
Phantop 2022-01-12 02:31:35 -05:00
parent 42ab34d36e
commit 7cc0501025
46 changed files with 5 additions and 1143 deletions

View File

Before

Width:  |  Height:  |  Size: 357 KiB

After

Width:  |  Height:  |  Size: 357 KiB

View File

@ -1,7 +1,7 @@
dial https://covid19.rpi.edu/dailycheckin
discord https://canary.discord.com/app
drop https://drop.lol
hn https://news.ycombinator.com
lms https://lms.rpi.edu
submitty https://submitty.cs.rpi.edu
hn https://darkhn.herokuapp.com
lms https://lms.rpi.edu/ultra/stream
submitty https://submitty.cs.rpi.edu/courses/s22/csci2200
tuta https://mail.tutanota.com

View File

@ -1,477 +0,0 @@
// ==UserScript==
// @name Hacker News - Bluish Gray
// @namespace https://github.com/pyxelr
// @description Bluish Gray Hacker News.
// @author pyxelr
// @homepage https://github.com/pyxelr/Hacker_News_-_Bluish_Gray
// @include http://news.ycombinator.com/*
// @include https://news.ycombinator.com/*
// @include http://*.news.ycombinator.com/*
// @include https://*.news.ycombinator.com/*
// @run-at document-start
// @version 1.2.2
// ==/UserScript==
(function IIFE() {
'use strict';
document.addEventListener('readystatechange', function onReadyStateChange() {
if (document.readyState == 'interactive') {
const style = document.createElement('style');
document.head.appendChild(style);
style.innerHTML = `
body {
background: #2b3033 !important;
color: #f0ffff !important;
font-family: "Open Sans", "Bitstream Vera Sans", Verdana, Geneva, sans-serif !important;
}
a:link { color:#b1bcbc !important; }
a:visited { color:#889191 !important; }
body > center > table[width="85%"] {
background: #212121 !important;
box-shadow: 0px 0px 30px 3px rgba(0, 0, 0, 0.2) !important;
border-left: 1px solid #000 !important;
border-right: 1px solid #000 !important;
}
/* ==== HEADER ==== */
/* header that's normally an orange bar at top (selects divider above footer too?) */
body > center > table[width="85%"] td[bgcolor="#ff6600"] {
background: linear-gradient(to top, #45515b 0%, #4b5762 100%) !important;
padding: 3px 4px !important;
box-shadow: 0px 1px 1px 0px rgba(33, 33, 33, 0.2);
}
/* "Hacker News" text in header */
.pagetop a[href="news"] {
font-size: 110% !important;
text-shadow: -1px -1px 0 #666, 1px -1px 0 #666, -1px 1px 0 #666, 1px 1px 0 #666 !important;
color: #e2e6e9 !important;
}
/* size reducement and black border around orange "Y" logo */
#hnmain > tbody > tr:first-of-type table img {
box-sizing: border-box;
border: 1px black solid !important;
}
/* currently selected link in header */
.topsel a {
color: #f93 !important;
font-weight: bold !important;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.7) !important;
}
/* hover link in header (except "Hacker News", and "login") */
.pagetop a:not(:first-child):hover {
text-decoration: underline !important;
}
.pagetop a:link:not(:first-child),
.pagetop a:visited:not(:first-child) {
color: #b1b1b1 !important;
}
/* colorize '|' characters in header (and hopefully nothing else) */
.pagetop {
color: #878f8f !important;
}
.pagetop > a[href^="user?"] {
color: #f0ffff !important;
}
/* ==== FRONT PAGE NEWS LISTING ==== */
.title {
font-size: 14px !important;
}
.title a.storylink:link {
color: #f0ffff !important;
}
.title a.storylink:visited {
color: #878f8f !important;
}
.storylink, .subtext {
padding-left: 8px !important;
}
.subtext {
padding-bottom: 8px !important;
font-size: 12px !important;
}
.itemlist .subtext, .itemlist .subtext * {
color: #878f8f !important;
}
.sitestr {
color: #6d7474 !important;
}
.title .rank {
padding-right: 8px !important;
padding-left: 8px !important;
color: #444848 !important;
font-size: 11px !important;
}
/* "More" link at bottom */
.morespace + tr a.morelink {
color: #b9d3d3 !important;
}
.votearrow {
filter: invert(100%) !important;
-webkit-filter: invert(100%) !important;
}
.subtext > a:last-child:visited {
color: #474f4f !important;
}
.subtext .hnuser {
font-weight: bold !important;
}
/* ==== COMMENTS ==== */
.comment,
.comment > span {
font-family: "Open Sans", "Bitstream Vera Sans", Verdana, Geneva, sans-serif !important;
font-size: 14px !important;
}
.comment .c00 {
color: #f0ffff !important;
}
.comhead .hnuser {
color: #abc3c3 !important;
font-weight: bold !important;
}
/* space between individual comments */
.athing.comtr .default {
padding-bottom: 10px !important;
}
.c5a, .c5a a:link, .c5a a:visited { opacity: 0.9 !important; }
.c73, .c73 a:link, .c73 a:visited { opacity: 0.8 !important; }
.c82, .c82 a:link, .c82 a:visited { opacity: 0.7 !important; }
.c88, .c88 a:link, .c88 a:visited { opacity: 0.6 !important; }
.c9c, .c9c a:link, .c9c a:visited { opacity: 0.5 !important; }
.cae, .cae a:link, .cae a:visited { opacity: 0.4 !important; }
.cbe, .cbe a:link, .cbe a:visited { opacity: 0.3 !important; }
.cce, .cce a:link, .cce a:visited { opacity: 0.2 !important; }
.cdd, .cdd a:link, .cdd a:visited { opacity: 0.1 !important; }
.c00, .c00 a:link,
.c5a, .c5a a:link, .c5a a:visited,
.c73, .c73 a:link, .c73 a:visited,
.c82, .c82 a:link, .c82 a:visited,
.c88, .c88 a:link, .c88 a:visited,
.c9c, .c9c a:link, .c9c a:visited,
.cae, .cae a:link, .cae a:visited,
.cbe, .cbe a:link, .cbe a:visited,
.cce, .cce a:link, .cce a:visited,
.cdd, .cdd a:link, .cdd a:visited
{
color:#f0ffff !important;
}
a[href^="reply"]:link {
color: #666c6c !important;
}
a[href^="reply"]:visited {
color: #333636 !important;
}
a[href^="reply"]:hover {
color: #abc3c3 !important;
}
/* animate opacity of dimmed comments */
.c5a, .c73, .c82, .c88, .c9c,
.cae, .cbe, .cce, .cdd {
transition: opacity 0.5s !important;
transition-duration: 0.4s !important;
transition-delay: 0.2s !important;
}
/* allow easier reading of dimmed comments */
.c5a:hover, .c73:hover, .c82:hover, .c88:hover, .c9c:hover,
.cae:hover, .cbe:hover, .cce:hover, .cdd:hover {
opacity: 1.0 !important;
}
.comhead {
color: #6d7474 !important;
}
.comment pre {
background: rgba(0, 0, 0, 0.2) !important;
}
.comment > span > a:link,
.comment > span > p a:link {
color: #abc3c3 !important;
}
.comment > span > a:visited,
.comment > span > p a:visited {
color: #505b5b !important;
}
.votearrow:hover {
filter: invert(100%) brightness(1.5) !important;
-webkit-filter: invert(100%) brightness(1.5) !important;
}
/* Ask HN text at top of commments */
#hnmain table:first-child tr[id].athing + tr + tr[style="height:2px"] + tr td {
font-family: "Open Sans", "Bitstream Vera Sans", Verdana, Geneva, sans-serif !important;
font-size: 15px !important;
color: #f0ffff !important;
/* line-height: 1.33 !important; */
}
/* ==== SEARCH BOX, COMMENT BOX, DROP-DOWN MENU ==== */
/* background color of search box, comment box and drop-down menu */
body > center > table, input, textarea, select {
background-color: #222 !important;
}
/* darker border around search box, comment box and drop-down menu*/
input, textarea, select {
border: 1px solid #828282 !important;
}
/* bright input text in search box, comment box and drop-down menu */
td.title a:link, span.comment font, span.comment font a:link, u a:link, span.yclinks a:link, body:not([id]),
td:nth-child(2):not(.subtext) > a:link, input, textarea, select, p > a, a > u, .c00, .c00 a:link,
a[href="http://www.ycombinator.com/apply/"] {
color: #ccc !important;
}
/* ==== FOOTER ==== */
#hnmain > tbody > tr:last-child {
background: linear-gradient(to bottom, #212121 0%, #131313 100%) !important;
}
#hnmain > tbody > tr:last-child td[bgcolor="#ff6600"] {
background: transparent !important;
border-top: 1px solid #778888 !important;
}
/* ==== OTHER ==== */
/* textbox formatting help */
.admin, .admin td, .admin p {
color: #f0ffff !important;
font-size: 14px !important;
}
/* bookmarklet text */
table[width="500"] #main > #first {
color: #000 !important;
}
}
@-moz-document domain("hn.algolia.com") {
/* invertion of algolia logo in the footer */
.search-wrapper img
{
filter: invert(50%) !important;
}
/* text highlight color of search results */
.main .search-results em {
background-color: #b1bcbc !important;
}
/* dark drop-down menus */
.wrap-dd-select
{
background-color: #222 !important;
border: 1px solid #828282 !important;
color: #ccc !important;
}
/* ==== SEARCH BOX, COMMENT BOX, DROP-DOWN MENU ==== */
/* Dropdown */
.Dropdown_label
{
color:#c2c2c2;
}
.Dropdown_list li button {
color: #f3f3f3;
background-color: #45515b;
}
/* Story */
.Story_title a
{
color: #F0FFFF;
}
.Story_title .Story_link
{
color: #6d7474;
font-size: 11px;
word-break: break-all;
}
.Story_comment
{
color: #ababab;
}
/* Search */
body > center > table, input, textarea, select
{
background-color: #222 !important;
}
.SearchResults_container
{
background-color: #222 !important;
}
.SearchFilters.container
{
background-color: #45515b !important;
}
.SearchFilters {
color: #f3f3f3;
}
.SearchHeader .PoweredBy
{
color:#a0a0a0;
}
.SearchResults
{
background:#222;
box-shadow: 0px 0px 30px 3px rgba(0, 0, 0, 0.2) !important;
border-left: 1px solid #000 !important;
border-right: 1px solid #000 !important;
}
/* Settings view */
.Settings
{
background-color:#222;
}
.Settings h2
{
color:#bcbcbc;
}
.Settings label
{
color:#a0a0a0;
}
/* Other */
.Pagination
{
background-color:#45515b;
}
.Footer_list a
{
color: #a0a0a0;
}
/* darker border around search box, comment box and drop-down menu*/
input, textarea, select {
border: 1px solid #828282 !important;
}
/* bright input text in search box, comment box and drop-down menu */
td.title a:link, span.comment font, span.comment font a:link, u a:link, span.yclinks a:link, body:not([id]),
td:nth-child(2):not(.subtext) > a:link, input, textarea, select, p > a, a > u, .c00, .c00 a:link,
a[href="http://www.ycombinator.com/apply/"] {
color: #ccc !important;
}
/* ==== OTHER ==== */
body {
background-color: #292929;
}
.search-results {
background-color: #292929;
}
.page-header a {
color: #9a9a9a;
}
.main .search-results .item .item-main .item-title-and-infos h2 a {
color: #9a9a9a;
}
#main > div > section > header {
background-color: #292929;
color: #9a9a9a;
}
.page-header .logo-wrapper .logo-name {
color: #e2e6e9 !important;
}
#main > div > header {
background-color: #292929;
color: #9a9a9a;
}
.main .search-results em {
background-color: #dadada !important; /* net net net :D */
}
.search-pagination li.active button {
border-color: #dadada;
color: #dadada;
}
footer {
background-color: #292929;
}
footer a {
color: #9a9a9a;
}
#main > div > section > section > section > div.item.ng-scope > div.item-main > div.item-content-wrapper p {
color: #dadada;
}
.edit-settings {
background-color: #292929;
}
`;
}
});
})();

View File

@ -1,661 +0,0 @@
// ==UserScript==
// @name TwitchAdSolutions (notify-strip)
// @namespace https://github.com/pixeltris/TwitchAdSolutions
// @version 1.11
// @updateURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @downloadURL https://github.com/pixeltris/TwitchAdSolutions/raw/master/notify-strip/notify-strip.user.js
// @description Multiple solutions for blocking Twitch ads (notify-strip)
// @author pixeltris
// @match *://*.twitch.tv/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function() {
'use strict';
function declareOptions(scope) {
// Options / globals
scope.OPT_ROLLING_DEVICE_ID = true;
scope.OPT_MODE_STRIP_AD_SEGMENTS = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED = true;
scope.OPT_MODE_NOTIFY_ADS_WATCHED_MIN_REQUESTS = false;
scope.OPT_MODE_NOTIFY_ADS_WATCHED_RELOAD_PLAYER_ON_AD_SEGMENT = false;
scope.OPT_BACKUP_PLAYER_TYPE = 'picture-by-picture';//'picture-by-picture';'thunderdome';
scope.OPT_REGULAR_PLAYER_TYPE = 'site';
scope.OPT_INITIAL_M3U8_ATTEMPTS = 1;
scope.OPT_ACCESS_TOKEN_PLAYER_TYPE = 'site';
scope.AD_SIGNIFIER = 'stitched-ad';
scope.LIVE_SIGNIFIER = ',live';
scope.CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
// These are only really for Worker scope...
scope.StreamInfos = [];
scope.StreamInfosByUrl = [];
scope.CurrentChannelNameFromM3U8 = null;
// Need this in both scopes. Window scope needs to update this to worker scope.
scope.gql_device_id = null;
scope.gql_device_id_rolling = '';
// Rolling device id crap... TODO: improve this
var charTable = []; for (var i = 97; i <= 122; i++) { charTable.push(String.fromCharCode(i)); } for (var i = 65; i <= 90; i++) { charTable.push(String.fromCharCode(i)); } for (var i = 48; i <= 57; i++) { charTable.push(String.fromCharCode(i)); }
var bs = 'eVI6jx47kJvCFfFowK86eVI6jx47kJvC';
var di = (new Date()).getUTCFullYear() + (new Date()).getUTCMonth() + ((new Date()).getUTCDate() / 7) | 0;
for (var i = 0; i < bs.length; i++) {
scope.gql_device_id_rolling += charTable[(bs.charCodeAt(i) ^ di) % charTable.length];
}
}
declareOptions(window);
var twitchMainWorker = null;
const oldWorker = window.Worker;
window.Worker = class Worker extends oldWorker {
constructor(twitchBlobUrl) {
if (twitchMainWorker) {
super(twitchBlobUrl);
return;
}
var jsURL = getWasmWorkerUrl(twitchBlobUrl);
if (typeof jsURL !== 'string') {
super(twitchBlobUrl);
return;
}
var newBlobStr = `
${processM3U8.toString()}
${hookWorkerFetch.toString()}
${declareOptions.toString()}
${getAccessToken.toString()}
${gqlRequest.toString()}
${makeGraphQlPacket.toString()}
${tryNotifyAdsWatchedM3U8.toString()}
${parseAttributes.toString()}
declareOptions(self);
self.addEventListener('message', function(e) {
if (e.data.key == 'UboUpdateDeviceId') {
gql_device_id = e.data.value;
}
});
hookWorkerFetch();
importScripts('${jsURL}');
`
super(URL.createObjectURL(new Blob([newBlobStr])));
twitchMainWorker = this;
this.onmessage = function(e) {
// NOTE: Removed adDiv caching as '.video-player' can change between streams?
if (e.data.key == 'UboShowAdBanner') {
var adDiv = getAdDiv();
if (adDiv != null) {
adDiv.P.textContent = 'Blocking' + (e.data.isMidroll ? ' midroll' : '') + ' ads...';
adDiv.style.display = 'block';
}
}
else if (e.data.key == 'UboHideAdBanner') {
var adDiv = getAdDiv();
if (adDiv != null) {
adDiv.style.display = 'none';
}
}
else if (e.data.key == 'UboFoundAdSegment') {
onFoundAd(e.data.isMidroll, e.data.streamM3u8);
}
else if (e.data.key == 'UboChannelNameM3U8Changed') {
//console.log('M3U8 channel name changed to ' + e.data.value);
}
else if (e.data.key == 'UboReloadPlayer') {
reloadTwitchPlayer();
}
else if (e.data.key == 'UboPauseResumePlayer') {
reloadTwitchPlayer(false, true);
}
else if (e.data.key == 'UboSeekPlayer') {
reloadTwitchPlayer(true);
}
}
function getAdDiv() {
var playerRootDiv = document.querySelector('.video-player');
var adDiv = null;
if (playerRootDiv != null) {
adDiv = playerRootDiv.querySelector('.ubo-overlay');
if (adDiv == null) {
adDiv = document.createElement('div');
adDiv.className = 'ubo-overlay';
adDiv.innerHTML = '<div class="player-ad-notice" style="color: white; background-color: rgba(0, 0, 0, 0.8); position: absolute; top: 0px; left: 0px; padding: 10px;"><p></p></div>';
adDiv.style.display = 'none';
adDiv.P = adDiv.querySelector('p');
playerRootDiv.appendChild(adDiv);
}
}
return adDiv;
}
}
}
function getWasmWorkerUrl(twitchBlobUrl) {
var req = new XMLHttpRequest();
req.open('GET', twitchBlobUrl, false);
req.send();
return req.responseText.split("'")[1];
}
async function processM3U8(url, textStr, realFetch) {
var streamInfo = StreamInfosByUrl[url];
if (streamInfo == null) {
console.log('Unknown stream url ' + url);
postMessage({key:'UboHideAdBanner'});
return textStr;
}
if (!OPT_MODE_STRIP_AD_SEGMENTS) {
return textStr;
}
var haveAdTags = textStr.includes(AD_SIGNIFIER);
if (haveAdTags) {
var currentResolution = null;
for (const [resUrl, resName] of Object.entries(streamInfo.Urls)) {
if (resUrl == url) {
currentResolution = resName;
//console.log(resName);
break;
}
}
streamInfo.HadAds[url] = true;
streamInfo.IsMidroll = textStr.includes('"MIDROLL"') || textStr.includes('"midroll"');
postMessage({key:'UboShowAdBanner',isMidroll:streamInfo.IsMidroll});
// Notify ads "watched" TODO: Keep crafting these requests even after ad tags are gone as sometimes it stops too early.
// Deferred to after backup obtained to reduce slowdown. Midrolls are futile.
if (OPT_MODE_NOTIFY_ADS_WATCHED && !streamInfo.IsMidroll && (streamInfo.BackupFailed || streamInfo.BackupUrl != null)) {
await tryNotifyAdsWatchedM3U8(textStr);
}
postMessage({
key: 'UboFoundAdSegment',
isMidroll: streamInfo.IsMidroll,
streamM3u8: textStr
});
if (!streamInfo.IsMidroll && OPT_MODE_NOTIFY_ADS_WATCHED_RELOAD_PLAYER_ON_AD_SEGMENT) {
return '';
}
// NOTE: Got a bit of code duplication here, merge Backup/BackupReg in some form.
// See if there's clean stream url to fetch (only do this after we have a regular backup, this should save time and you're unlikely to find a clean stream on first request)
try {
if (streamInfo.BackupRegRes != currentResolution) {
streamInfo.BackupRegRes = null;
streamInfo.BackupRegUrl = null;
}
if (currentResolution && streamInfo.BackupRegUrl == null && (streamInfo.BackupFailed || streamInfo.BackupUrl != null)) {
var accessTokenResponse = await getAccessToken(streamInfo.ChannelName, OPT_REGULAR_PLAYER_TYPE);
if (accessTokenResponse.status === 200) {
var accessToken = await accessTokenResponse.json();
var urlInfo = new URL('https://usher.ttvnw.net/api/channel/hls/' + streamInfo.ChannelName + '.m3u8' + streamInfo.RootM3U8Params);
urlInfo.searchParams.set('sig', accessToken.data.streamPlaybackAccessToken.signature);
urlInfo.searchParams.set('token', accessToken.data.streamPlaybackAccessToken.value);
var encodingsM3u8Response = await realFetch(urlInfo.href);
if (encodingsM3u8Response.status === 200) {
var encodingsM3u8 = await encodingsM3u8Response.text();
var encodingsLines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < encodingsLines.length; i++) {
if (!encodingsLines[i].startsWith('#') && encodingsLines[i].includes('.m3u8')) {
if (i > 0 && encodingsLines[i - 1].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(encodingsLines[i - 1])['RESOLUTION'];
if (res && res == currentResolution) {
streamInfo.BackupRegUrl = encodingsLines[i];
streamInfo.BackupRegRes = currentResolution;
break;
}
}
}
}
}
}
}
if (streamInfo.BackupRegUrl != null) {
var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupRegUrl);
if (backupM3u8Response.status == 200) {
backupM3u8 = await backupM3u8Response.text();
}
if (backupM3u8 != null && !backupM3u8.includes(AD_SIGNIFIER)) {
return backupM3u8;
} else {
//console.log('Try use regular resolution failed');
streamInfo.BackupRegRes = null;
streamInfo.BackupRegUrl = null;
}
}
} catch (err) {
streamInfo.BackupRegRes = null;
streamInfo.BackupRegUrl = null;
console.log('Fetching backup (regular resolution) m3u8 failed');
console.log(err);
}
// Fetch backup url
try {
if (!streamInfo.BackupFailed && streamInfo.BackupUrl == null) {
// NOTE: We currently don't fetch the oauth_token. You wont be able to access private streams like this.
streamInfo.BackupFailed = true;
var accessTokenResponse = await getAccessToken(streamInfo.ChannelName, OPT_BACKUP_PLAYER_TYPE);
if (accessTokenResponse.status === 200) {
var accessToken = await accessTokenResponse.json();
var urlInfo = new URL('https://usher.ttvnw.net/api/channel/hls/' + streamInfo.ChannelName + '.m3u8' + streamInfo.RootM3U8Params);
urlInfo.searchParams.set('sig', accessToken.data.streamPlaybackAccessToken.signature);
urlInfo.searchParams.set('token', accessToken.data.streamPlaybackAccessToken.value);
var encodingsM3u8Response = await realFetch(urlInfo.href);
if (encodingsM3u8Response.status === 200) {
// TODO: Maybe look for the most optimal m3u8
var encodingsM3u8 = await encodingsM3u8Response.text();
var streamM3u8Url = encodingsM3u8.match(/^https:.*\.m3u8$/m)[0];
// Maybe this request is a bit unnecessary
var streamM3u8Response = await realFetch(streamM3u8Url);
if (streamM3u8Response.status == 200) {
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = streamM3u8Url;
console.log('Fetched backup url: ' + streamInfo.BackupUrl);
} else {
console.log('Backup url request (streamM3u8) failed with ' + streamM3u8Response.status);
}
} else {
console.log('Backup url request (encodingsM3u8) failed with ' + encodingsM3u8Response.status);
}
} else {
console.log('Backup url request (accessToken) failed with ' + accessTokenResponse.status);
}
}
if (streamInfo.BackupUrl != null) {
var backupM3u8 = null;
var backupM3u8Response = await realFetch(streamInfo.BackupUrl);
if (backupM3u8Response.status == 200) {
backupM3u8 = await backupM3u8Response.text();
}
if (backupM3u8 != null && !backupM3u8.includes(AD_SIGNIFIER)) {
return backupM3u8;
} else {
console.log('Backup m3u8 failed with ' + backupM3u8Response.status);
}
}
} catch (err) {
console.log('Fetching backup m3u8 failed');
console.log(err);
}
// Backups failed. Return nothing and reload the player (reload required as an empty result will terminate the stream).
console.log('Ad blocking failed. Stream might break.');
postMessage({key:'UboReloadPlayer'});
streamInfo.BackupFailed = false;
streamInfo.BackupUrl = null;
return '';
}
if (streamInfo.HadAds[url]) {
postMessage({key:'UboPauseResumePlayer'});
streamInfo.HadAds[url] = false;
}
postMessage({key:'UboHideAdBanner'});
return textStr;
}
function hookWorkerFetch() {
var realFetch = fetch;
fetch = async function(url, options) {
if (typeof url === 'string') {
if (url.endsWith('m3u8')) {
return new Promise(function(resolve, reject) {
var processAfter = async function(response) {
var str = await processM3U8(url, await response.text(), realFetch);
resolve(new Response(str));
};
var send = function() {
return realFetch(url, options).then(function(response) {
processAfter(response);
})['catch'](function(err) {
console.log('fetch hook err ' + err);
reject(err);
});
};
send();
});
}
else if (url.includes('/api/channel/hls/') && !url.includes('picture-by-picture')) {
var channelName = (new URL(url)).pathname.match(/([^\/]+)(?=\.\w+$)/)[0];
if (CurrentChannelNameFromM3U8 != channelName) {
postMessage({
key: 'UboChannelNameM3U8Changed',
value: channelName
});
}
CurrentChannelNameFromM3U8 = channelName;
if (OPT_MODE_STRIP_AD_SEGMENTS) {
return new Promise(async function(resolve, reject) {
// - First m3u8 request is the m3u8 with the video encodings (360p,480p,720p,etc).
// - Second m3u8 request is the m3u8 for the given encoding obtained in the first request. At this point we will know if there's ads.
var maxAttempts = OPT_INITIAL_M3U8_ATTEMPTS <= 0 ? 1 : OPT_INITIAL_M3U8_ATTEMPTS;
var attempts = 0;
while(true) {
var encodingsM3u8Response = await realFetch(url, options);
if (encodingsM3u8Response.status === 200) {
var encodingsM3u8 = await encodingsM3u8Response.text();
var streamM3u8Url = encodingsM3u8.match(/^https:.*\.m3u8$/m)[0];
var streamM3u8Response = await realFetch(streamM3u8Url);
var streamM3u8 = await streamM3u8Response.text();
if (!streamM3u8.includes(AD_SIGNIFIER) || ++attempts >= maxAttempts) {
if (maxAttempts > 1 && attempts >= maxAttempts) {
console.log('max skip ad attempts reached (attempt #' + attempts + ')');
}
var streamInfo = StreamInfos[channelName];
if (streamInfo == null) {
StreamInfos[channelName] = streamInfo = {};
}
// This might potentially backfire... maybe just add the new urls
streamInfo.ChannelName = channelName;
streamInfo.Urls = [];// xxx.m3u8 -> "284x160" (resolution)
streamInfo.RootM3U8Url = url;
streamInfo.RootM3U8Params = (new URL(url)).search;
streamInfo.BackupUrl = null;
streamInfo.BackupFailed = false;
streamInfo.BackupRegUrl = null;
streamInfo.BackupRegRes = null;
streamInfo.IsMidroll = false;
streamInfo.HadAds = [];// xxx.m3u8 -> bool (had ads on prev request)
var lines = encodingsM3u8.replace('\r', '').split('\n');
for (var i = 0; i < lines.length; i++) {
if (!lines[i].startsWith('#') && lines[i].includes('.m3u8')) {
streamInfo.Urls[lines[i]] = -1;
if (i > 0 && lines[i - 1].startsWith('#EXT-X-STREAM-INF')) {
var res = parseAttributes(lines[i - 1])['RESOLUTION'];
if (res) {
streamInfo.Urls[lines[i]] = res;
}
}
streamInfo.HadAds[lines[i]] = false;
StreamInfosByUrl[lines[i]] = streamInfo;
}
}
resolve(new Response(encodingsM3u8));
break;
}
console.log('attempt to skip ad (attempt #' + attempts + ')');
} else {
// Stream is offline?
resolve(encodingsM3u8Response);
break;
}
}
});
}
}
}
return realFetch.apply(this, arguments);
}
}
function makeGraphQlPacket(event, radToken, payload) {
return [{
operationName: 'ClientSideAdEventHandling_RecordAdEvent',
variables: {
input: {
eventName: event,
eventPayload: JSON.stringify(payload),
radToken,
},
},
extensions: {
persistedQuery: {
version: 1,
sha256Hash: '7e6c69e6eb59f8ccb97ab73686f3d8b7d85a72a0298745ccd8bfc68e4054ca5b',
},
},
}];
}
function getAccessToken(channelName, playerType, realFetch) {
var body = null;
var templateQuery = 'query PlaybackAccessToken_Template($login: String!, $isLive: Boolean!, $vodID: ID!, $isVod: Boolean!, $playerType: String!) { streamPlaybackAccessToken(channelName: $login, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isLive) { value signature __typename } videoPlaybackAccessToken(id: $vodID, params: {platform: "web", playerBackend: "mediaplayer", playerType: $playerType}) @include(if: $isVod) { value signature __typename }}';
body = {
operationName: 'PlaybackAccessToken_Template',
query: templateQuery,
variables: {
'isLive': true,
'login': channelName,
'isVod': false,
'vodID': '',
'playerType': playerType
}
};
return gqlRequest(body, realFetch);
}
function gqlRequest(body, realFetch) {
var fetchFunc = realFetch ? realFetch : fetch;
return fetchFunc('https://gql.twitch.tv/gql', {
method: 'POST',
body: JSON.stringify(body),
headers: {
'client-id': CLIENT_ID,
'X-Device-Id': OPT_ROLLING_DEVICE_ID ? gql_device_id_rolling : gql_device_id
}
});
}
function parseAttributes(str) {
return Object.fromEntries(
str.split(/(?:^|,)((?:[^=]*)=(?:"[^"]*"|[^,]*))/)
.filter(Boolean)
.map(x => {
const idx = x.indexOf('=');
const key = x.substring(0, idx);
const value = x.substring(idx +1);
const num = Number(value);
return [key, Number.isNaN(num) ? value.startsWith('"') ? JSON.parse(value) : value : num]
}));
}
async function tryNotifyAdsWatchedM3U8(streamM3u8) {
try {
//console.log(streamM3u8);
if (!streamM3u8.includes(AD_SIGNIFIER)) {
return 1;
}
var matches = streamM3u8.match(/#EXT-X-DATERANGE:(ID="stitched-ad-[^\n]+)\n/);
if (matches.length > 1) {
const attrString = matches[1];
const attr = parseAttributes(attrString);
var podLength = parseInt(attr['X-TV-TWITCH-AD-POD-LENGTH'] ? attr['X-TV-TWITCH-AD-POD-LENGTH'] : '1');
var podPosition = parseInt(attr['X-TV-TWITCH-AD-POD-POSITION'] ? attr['X-TV-TWITCH-AD-POD-POSITION'] : '0');
var radToken = attr['X-TV-TWITCH-AD-RADS-TOKEN'];
var lineItemId = attr['X-TV-TWITCH-AD-LINE-ITEM-ID'];
var orderId = attr['X-TV-TWITCH-AD-ORDER-ID'];
var creativeId = attr['X-TV-TWITCH-AD-CREATIVE-ID'];
var adId = attr['X-TV-TWITCH-AD-ADVERTISER-ID'];
var rollType = attr['X-TV-TWITCH-AD-ROLL-TYPE'].toLowerCase();
const baseData = {
stitched: true,
roll_type: rollType,
player_mute: false,
player_volume: 0.5,
visible: true,
};
for (let podPosition = 0; podPosition < podLength; podPosition++) {
if (OPT_MODE_NOTIFY_ADS_WATCHED_MIN_REQUESTS) {
// This is all that's actually required at the moment
await gqlRequest(makeGraphQlPacket('video_ad_pod_complete', radToken, baseData));
} else {
const extendedData = {
...baseData,
ad_id: adId,
ad_position: podPosition,
duration: 30,
creative_id: creativeId,
total_ads: podLength,
order_id: orderId,
line_item_id: lineItemId,
};
await gqlRequest(makeGraphQlPacket('video_ad_impression', radToken, extendedData));
for (let quartile = 0; quartile < 4; quartile++) {
await gqlRequest(
makeGraphQlPacket('video_ad_quartile_complete', radToken, {
...extendedData,
quartile: quartile + 1,
})
);
}
await gqlRequest(makeGraphQlPacket('video_ad_pod_complete', radToken, baseData));
}
}
}
return 0;
} catch (err) {
console.log(err);
return 0;
}
}
function hookFetch() {
var realFetch = window.fetch;
window.fetch = function(url, init, ...args) {
if (typeof url === 'string') {
if (url.includes('/access_token') || url.includes('gql')) {
if (OPT_ACCESS_TOKEN_PLAYER_TYPE) {
if (url.includes('gql') && init && typeof init.body === 'string' && init.body.includes('PlaybackAccessToken')) {
const newBody = JSON.parse(init.body);
newBody.variables.playerType = OPT_ACCESS_TOKEN_PLAYER_TYPE;
init.body = JSON.stringify(newBody);
}
}
var deviceId = init.headers['X-Device-Id'];
if (typeof deviceId !== 'string') {
deviceId = init.headers['Device-ID'];
}
if (typeof deviceId === 'string') {
gql_device_id = deviceId;
}
if (gql_device_id && twitchMainWorker) {
twitchMainWorker.postMessage({
key: 'UboUpdateDeviceId',
value: gql_device_id
});
}
if (OPT_ROLLING_DEVICE_ID) {
if (typeof init.headers['X-Device-Id'] === 'string') {
init.headers['X-Device-Id'] = gql_device_id_rolling;
}
if (typeof init.headers['Device-ID'] === 'string') {
init.headers['Device-ID'] = gql_device_id_rolling;
}
}
}
}
return realFetch.apply(this, arguments);
}
}
function onFoundAd(isMidroll, streamM3u8) {
if (OPT_MODE_NOTIFY_ADS_WATCHED_RELOAD_PLAYER_ON_AD_SEGMENT && !isMidroll) {
console.log('OPT_MODE_NOTIFY_ADS_WATCHED_RELOAD_PLAYER_ON_AD_SEGMENT');
if (streamM3u8) {
tryNotifyAdsWatchedM3U8(streamM3u8);
}
reloadTwitchPlayer();
}
}
function reloadTwitchPlayer(isSeek, isPausePlay) {
// Taken from ttv-tools / ffz
// https://github.com/Nerixyz/ttv-tools/blob/master/src/context/twitch-player.ts
// https://github.com/FrankerFaceZ/FrankerFaceZ/blob/master/src/sites/twitch-twilight/modules/player.jsx
function findReactNode(root, constraint) {
if (root.stateNode && constraint(root.stateNode)) {
return root.stateNode;
}
let node = root.child;
while (node) {
const result = findReactNode(node, constraint);
if (result) {
return result;
}
node = node.sibling;
}
return null;
}
var reactRootNode = null;
var rootNode = document.querySelector('#root');
if (rootNode && rootNode._reactRootContainer && rootNode._reactRootContainer._internalRoot && rootNode._reactRootContainer._internalRoot.current) {
reactRootNode = rootNode._reactRootContainer._internalRoot.current;
}
if (!reactRootNode) {
console.log('Could not find react root');
return;
}
var player = findReactNode(reactRootNode, node => node.setPlayerActive && node.props && node.props.mediaPlayerInstance);
player = player && player.props && player.props.mediaPlayerInstance ? player.props.mediaPlayerInstance : null;
var playerState = findReactNode(reactRootNode, node => node.setSrc && node.setInitialPlaybackSettings);
if (!player) {
console.log('Could not find player');
return;
}
if (!playerState) {
console.log('Could not find player state');
return;
}
if (player.paused) {
return;
}
if (isSeek) {
console.log('Force seek to reset player (hopefully fixing any audio desync) pos:' + player.getPosition() + ' range:' + JSON.stringify(player.getBuffered()));
var pos = player.getPosition();
player.seekTo(0);
player.seekTo(pos);
return;
}
if (isPausePlay) {
player.pause();
player.play();
return;
}
const sink = player.mediaSinkManager || (player.core ? player.core.mediaSinkManager : null);
if (sink && sink.video && sink.video._ffz_compressor) {
const video = sink.video;
const volume = video.volume ? video.volume : player.getVolume();
const muted = player.isMuted();
const newVideo = document.createElement('video');
newVideo.volume = muted ? 0 : volume;
newVideo.playsInline = true;
video.replaceWith(newVideo);
player.attachHTMLVideoElement(newVideo);
setImmediate(() => {
player.setVolume(volume);
player.setMuted(muted);
});
}
playerState.setSrc({ isNewMediaPlayerInstance: true, refreshAccessToken: true });// ffz sets this false
}
window.reloadTwitchPlayer = reloadTwitchPlayer;
hookFetch();
function onContentLoaded() {
// This stops Twitch from pausing the player when in another tab and an ad shows.
// Taken from https://github.com/saucettv/VideoAdBlockForTwitch/blob/cefce9d2b565769c77e3666ac8234c3acfe20d83/chrome/content.js#L30
try {
Object.defineProperty(document, 'visibilityState', {
get() {
return 'visible';
}
});
}catch{}
try {
Object.defineProperty(document, 'hidden', {
get() {
return false;
}
});
}catch{}
var block = e => {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
};
document.addEventListener('visibilitychange', block, true);
document.addEventListener('webkitvisibilitychange', block, true);
document.addEventListener('mozvisibilitychange', block, true);
document.addEventListener('hasFocus', block, true);
try {
if (/Firefox/.test(navigator.userAgent)) {
Object.defineProperty(document, 'mozHidden', {
get() {
return false;
}
});
} else {
Object.defineProperty(document, 'webkitHidden', {
get() {
return false;
}
});
}
}catch{}
}
if (document.readyState === "complete" || document.readyState === "loaded" || document.readyState === "interactive") {
onContentLoaded();
} else {
window.addEventListener("DOMContentLoaded", function() {
onContentLoaded();
});
}
})();

View File

@ -20,7 +20,7 @@ ln -s ~/.config/gtkrc ~/.gtkrc-2.0
install -D <(echo set -g mouse on) ~/.config/tmux/tmux.conf
mkdir -p ~/.parallel/will-cite
parallel stow --no-folding -d ~/.dotfiles/dot-{} -t ~/.{} . ::: config local
parallel stow --no-folding -d ~/.dotfiles/{} -t ~/.{} . ::: config local
un(){ F=$(mktemp); mkdir -p $2; curl https://api.github.com/repos/$1/releases |\
grep -om1 http.\*zip | wget -i- -O$F; unzip $F -d $2;}

2
setup
View File

@ -1 +1 @@
dot-local/bin/setup
local/bin/setup