|
// ==UserScript== |
|
// @name SponsorBlock clickable startTime (sb.ltn.fi) |
|
// @namespace sb.ltn.fi.clickable.starttime |
|
// @version 1.0.6 |
|
// @description Makes the startTime clickable |
|
// @author Nanobyte |
|
// @match https://sb.ltn.fi/* |
|
// @updateURL https://gist.github.com/MRuy/ca74d6a359c487d760f4a698e76fb0d6/raw/sb.ltn.fi.clickablestarttime.user.js |
|
// @downloadURL https://gist.github.com/MRuy/ca74d6a359c487d760f4a698e76fb0d6/raw/sb.ltn.fi.clickablestarttime.user.js |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
let videoId = ''; |
|
const pathArr = window.location.pathname.split('/'); |
|
if (pathArr.length > 1) { |
|
switch(pathArr[1]) { |
|
case 'video': |
|
{ |
|
const videoFolderIndex = pathArr.indexOf('video'); |
|
if (videoFolderIndex !== -1) { |
|
videoId = pathArr[videoFolderIndex + 1]; |
|
} |
|
} |
|
break; |
|
case 'uuid': |
|
{ |
|
const elYtLink = document.querySelector('.list-group-item a[href*="youtube.com/watch"]'); |
|
if (elYtLink) { |
|
const url = new URL(elYtLink.href); |
|
if (url.searchParams.has('v')) { |
|
videoId = url.searchParams.get('v'); |
|
} |
|
|
|
} |
|
} |
|
break; |
|
default: |
|
{ |
|
const searchParams = new URLSearchParams(window.location.search); |
|
if (searchParams.has('v')) { |
|
videoId = searchParams.get('v'); |
|
} |
|
} |
|
} |
|
} |
|
if (window.location.pathname.includes('/video/')) { |
|
const folders = window.location.pathname.split('/'); |
|
const videoFolderIndex = folders.indexOf('video'); |
|
if (videoFolderIndex !== -1) { |
|
videoId = folders[videoFolderIndex + 1]; |
|
} |
|
} |
|
else { |
|
const searchParams = new URLSearchParams(window.location.search); |
|
if (searchParams.has('v')) { |
|
videoId = searchParams.get('v'); |
|
} |
|
} |
|
|
|
(function() { |
|
'use strict'; |
|
|
|
[...document.querySelectorAll('table')].forEach(table => { |
|
const headers = [...table.querySelectorAll('thead th')].map(item => item.textContent.trim()); |
|
if (headers.includes('Start') && headers.includes('End')) { |
|
const startColumnIndex = headers.indexOf('Start'); |
|
const videoIDColumnIndex = headers.indexOf('VideoID'); |
|
const uuidColumnIndex = headers.indexOf('UUID'); |
|
const rows = [...table.querySelectorAll('tbody tr')]; |
|
|
|
rows.forEach(row => { |
|
const cellEl = row.children[startColumnIndex]; |
|
if (videoIDColumnIndex !== -1) { |
|
videoId = row.children[videoIDColumnIndex].children[0].textContent.trim(); |
|
} |
|
const UUID = row.children[uuidColumnIndex].querySelector('textarea').value; |
|
let content = cellEl.textContent.trim(); |
|
const link = document.createElement('a'); |
|
let startTimeSeconds = content.split('.')[0].split(':').map(s=>Number(s)).reverse().map((val,index) => { |
|
return [1, 60, 3600][index] * val; |
|
}).reduce((acc, curr)=>acc+curr, 0); |
|
link.textContent = content; |
|
link.style.color = 'inherit'; |
|
const seekTime = Math.max(0, startTimeSeconds - 2); |
|
link.href = `https://www.youtube.com/watch?v=${videoId}${seekTime===0?'':'&t='+seekTime+'s'}#requiredSegment=${UUID}`; |
|
cellEl.innerHTML = ''; |
|
cellEl.appendChild(link); |
|
}); |
|
} |
|
}); |
|
})(); |
|
|
|
function wrapElement(target, el) { |
|
el.innerHTML = target.innerHTML; |
|
target.innerHTML = el.innerHTML |
|
} |