|
// ==UserScript== |
|
// @name SponsorBlock similar segments (sb.ltn.fi) |
|
// @namespace sb.ltn.fi.sponsorblock.similar.segments |
|
// @version 1.1.0 |
|
// @description Color highlights segments that are similar on sb.ltn.fi (Only works on video page sorted by starttime) |
|
// @author Nanobyte |
|
// @match https://sb.ltn.fi/*videoid=*sort=*starttime* |
|
// @match https://sb.ltn.fi/video/*/*sort=*starttime* |
|
// @match https://sb.ltn.fi/uuid/*/*?sort=starttime* |
|
// @updateURL https://gist.github.com/MRuy/ca74d6a359c487d760f4a698e76fb0d6/raw/sb.ltn.fi.similarsegments.user.js |
|
// @downloadURL https://gist.github.com/MRuy/ca74d6a359c487d760f4a698e76fb0d6/raw/sb.ltn.fi.similarsegments.user.js |
|
// @grant none |
|
// ==/UserScript== |
|
|
|
const COLORS = '#278ecf,#4bd762,#ffca1f,#ff9416,#d42ae8,#535ad7,#ff402c,#83bfff,#6edb8f,#ffe366,#ffc266,#d284bd,#8784db,#ff7b65,#caeefc,#9adbad,#fff1b2,#ffe0b2,#ffbeb2,#b1afdb'.split(','); |
|
const COLOR_LEN = COLORS.length; |
|
|
|
(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 startIndex = headers.indexOf('Start'); |
|
const endIndex = headers.indexOf('End'); |
|
const rows = [...table.querySelectorAll('tbody tr')]; |
|
|
|
let lastStarttime = 0; |
|
let lastEndtime = 0; |
|
let matchGroupIndex = 0; |
|
rows.forEach(row => { |
|
const startEl = row.children[startIndex]; |
|
const endEl = row.children[endIndex]; |
|
const start = parseTime(startEl.textContent.trim()); |
|
const end = parseTime(endEl.textContent.trim()); |
|
|
|
if (isInRange(lastStarttime, start) && isInRange(lastEndtime, end)) { |
|
let color = COLORS[matchGroupIndex % COLOR_LEN]; |
|
wrapElementWithColor(startEl, color); |
|
wrapElementWithColor(endEl, color); |
|
} else { |
|
matchGroupIndex++; |
|
let color = COLORS[matchGroupIndex % COLOR_LEN]; |
|
wrapElementWithColor(startEl, color); |
|
wrapElementWithColor(endEl, color); |
|
} |
|
lastStarttime = start; |
|
lastEndtime = end; |
|
}); |
|
} |
|
}); |
|
})(); |
|
|
|
function parseTime(str) { |
|
const [hours, minutes, seconds] = str.split(':').map(str => parseFloat(str)); |
|
return seconds + (minutes * 60) + (hours * 3600); |
|
} |
|
|
|
function isInRange(val1, val2, offset=2) { |
|
if (val1 > val2 - offset && val1 < val2 + offset) { |
|
return true; |
|
} |
|
return false; |
|
} |
|
|
|
function wrapElementWithColor(el, color) { |
|
let wrapper = document.createElement("td"); |
|
el.parentNode.insertBefore(wrapper, el); |
|
el.style = `padding:1px 4px;color:#000;width:100%;border-radius:4px;background:${color}` |
|
wrapper.appendChild(el) |
|
} |