mirror of
https://github.com/lawrencehook/remove-youtube-suggestions.git
synced 2026-07-25 06:54:31 +00:00
Tidy: convert tab-indented files to 4-space (#217)
Project convention is 4-space indent for extension JS, but src/shared/utils.js and one function in src/shared/analytics.js used tabs. Converted leading tabs to 4 spaces, no functional change. Also fixed a misaligned line at utils.js:63 that had a single leading space instead of the expected indent. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,10 +4,10 @@ for(h=0;h<i.length;h++)g(a,i[h]);var j="set set_once union unset remove delete".
|
|||||||
mixpanel.init('44d2dff3b4d141679640b297d31d5093');
|
mixpanel.init('44d2dff3b4d141679640b297d31d5093');
|
||||||
|
|
||||||
function recordEvent(name, props={}) {
|
function recordEvent(name, props={}) {
|
||||||
const logEnabled = document.documentElement.getAttribute('log_enabled') || 'false';
|
const logEnabled = document.documentElement.getAttribute('log_enabled') || 'false';
|
||||||
|
|
||||||
if (logEnabled !== 'true') return;
|
if (logEnabled !== 'true') return;
|
||||||
|
|
||||||
props.extension_version = browser.runtime.getManifest().version;
|
props.extension_version = browser.runtime.getManifest().version;
|
||||||
mixpanel.track(name, props);
|
mixpanel.track(name, props);
|
||||||
}
|
}
|
||||||
|
|||||||
+93
-93
@@ -14,144 +14,144 @@ const subsRegex = new RegExp(/\/feed\/subscriptions$/, 'i');
|
|||||||
|
|
||||||
/* Scheduling */
|
/* Scheduling */
|
||||||
function timeIsValid(times) {
|
function timeIsValid(times) {
|
||||||
const timeRegex = /^([1-9]|1[012]):[0-5][0-9](a|p)-([1-9]|1[012]):[0-5][0-9](a|p)$/i;
|
const timeRegex = /^([1-9]|1[012]):[0-5][0-9](a|p)-([1-9]|1[012]):[0-5][0-9](a|p)$/i;
|
||||||
return times.split(',').every(time => {
|
return times.split(',').every(time => {
|
||||||
return timeRegex.test(time.trim());
|
return timeRegex.test(time.trim());
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: Check that the start time is before the end time.
|
// TODO: Check that the start time is before the end time.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const DAYS = ['su','mo','tu','we','th','fr','sa'];
|
const DAYS = ['su','mo','tu','we','th','fr','sa'];
|
||||||
function checkSchedule(times, days, now=new Date()) {
|
function checkSchedule(times, days, now=new Date()) {
|
||||||
if (!times || !days) return false;
|
if (!times || !days) return false;
|
||||||
|
|
||||||
const currDay = DAYS[now.getDay()];
|
const currDay = DAYS[now.getDay()];
|
||||||
const daysArray = days.split(',').map(d => d.toLowerCase().trim());
|
const daysArray = days.split(',').map(d => d.toLowerCase().trim());
|
||||||
|
|
||||||
if (!daysArray.includes(currDay)) return false;
|
if (!daysArray.includes(currDay)) return false;
|
||||||
|
|
||||||
const timesArray = times.split(',').map(t => t.toLowerCase().trim());
|
const timesArray = times.split(',').map(t => t.toLowerCase().trim());
|
||||||
const matchFound = timesArray.some(time => {
|
const matchFound = timesArray.some(time => {
|
||||||
const [ startString, endString ] = time.split('-');
|
const [ startString, endString ] = time.split('-');
|
||||||
const startTime = parseScheduleTime(startString.trim(), now);
|
const startTime = parseScheduleTime(startString.trim(), now);
|
||||||
|
|
||||||
// TODO -> force endTime to come after startTime
|
// TODO -> force endTime to come after startTime
|
||||||
const endTime = parseScheduleTime(endString.trim(), now);
|
const endTime = parseScheduleTime(endString.trim(), now);
|
||||||
|
|
||||||
return now > startTime && now < endTime;
|
return now > startTime && now < endTime;
|
||||||
});
|
});
|
||||||
|
|
||||||
return matchFound;
|
return matchFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parseScheduleTime(time, now) {
|
function parseScheduleTime(time, now) {
|
||||||
if (!time || !now) return;
|
if (!time || !now) return;
|
||||||
|
|
||||||
const period = time.slice(-1);
|
const period = time.slice(-1);
|
||||||
const [ hours, minutes ] = time.slice(0, -1).split(':');
|
const [ hours, minutes ] = time.slice(0, -1).split(':');
|
||||||
|
|
||||||
const hoursNum = Number(hours);
|
const hoursNum = Number(hours);
|
||||||
let trueHours;
|
let trueHours;
|
||||||
if (hoursNum === 12 && period === 'a') {
|
if (hoursNum === 12 && period === 'a') {
|
||||||
trueHours = 0;
|
trueHours = 0;
|
||||||
} else if (hoursNum === 12 && period === 'p') {
|
} else if (hoursNum === 12 && period === 'p') {
|
||||||
trueHours = 12;
|
trueHours = 12;
|
||||||
} else if (period === 'p') {
|
} else if (period === 'p') {
|
||||||
trueHours = hoursNum + 12;
|
trueHours = hoursNum + 12;
|
||||||
} else {
|
} else {
|
||||||
trueHours = hoursNum;
|
trueHours = hoursNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeInDay = new Date(now).setHours(trueHours, minutes, 0, 0);
|
const timeInDay = new Date(now).setHours(trueHours, minutes, 0, 0);
|
||||||
return timeInDay;
|
return timeInDay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function nextScheduleChange(times, days) {
|
function nextScheduleChange(times, days) {
|
||||||
if (!times || !days) return;
|
if (!times || !days) return;
|
||||||
|
|
||||||
const current = checkSchedule(times, days);
|
const current = checkSchedule(times, days);
|
||||||
const MIN_IN_WEEK = 10_080;
|
const MIN_IN_WEEK = 10_080;
|
||||||
let testDate = new Date();
|
let testDate = new Date();
|
||||||
testDate.setSeconds(0);
|
testDate.setSeconds(0);
|
||||||
let next = checkSchedule(times, days, testDate);
|
let next = checkSchedule(times, days, testDate);
|
||||||
let i = 0;
|
let i = 0;
|
||||||
while (current === next && i < MIN_IN_WEEK) {
|
while (current === next && i < MIN_IN_WEEK) {
|
||||||
i += 1;
|
i += 1;
|
||||||
testDate = new Date(testDate.getTime() + 60_000);
|
testDate = new Date(testDate.getTime() + 60_000);
|
||||||
next = checkSchedule(times, days, testDate);
|
next = checkSchedule(times, days, testDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i >= MIN_IN_WEEK) return;
|
if (i >= MIN_IN_WEEK) return;
|
||||||
|
|
||||||
return testDate;
|
return testDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function formatDateMessage(date) {
|
function formatDateMessage(date) {
|
||||||
if (!date) return 'unknown date';
|
if (!date) return 'unknown date';
|
||||||
return date.toLocaleDateString('en-us', {
|
return date.toLocaleDateString('en-us', {
|
||||||
weekday:"long",
|
weekday:"long",
|
||||||
month:"long",
|
month:"long",
|
||||||
hour12: true,
|
hour12: true,
|
||||||
day:"numeric",
|
day:"numeric",
|
||||||
hour: "numeric",
|
hour: "numeric",
|
||||||
minute: "numeric",
|
minute: "numeric",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function formatDateMessageShort(date) {
|
function formatDateMessageShort(date) {
|
||||||
if (!date) return 'unknown date';
|
if (!date) return 'unknown date';
|
||||||
return date.toLocaleDateString('en-us', {
|
return date.toLocaleDateString('en-us', {
|
||||||
hour: "numeric",
|
hour: "numeric",
|
||||||
minute: "numeric",
|
minute: "numeric",
|
||||||
}).match(/[0-9]{1,2}:[0-9]{1,2}.*/)[0].toLowerCase();
|
}).match(/[0-9]{1,2}:[0-9]{1,2}.*/)[0].toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function parseTimeRemaining(ms) {
|
function parseTimeRemaining(ms) {
|
||||||
const seconds = Math.floor((ms / (1000)) % 60);
|
const seconds = Math.floor((ms / (1000)) % 60);
|
||||||
const minutes = Math.floor((ms / (60 * 1000)) % 60);
|
const minutes = Math.floor((ms / (60 * 1000)) % 60);
|
||||||
const hours = Math.floor((ms / (60 * 60 * 1000)) % 24);
|
const hours = Math.floor((ms / (60 * 60 * 1000)) % 24);
|
||||||
const days = Math.floor(ms / (60 * 60 * 24 * 1000) % 7);
|
const days = Math.floor(ms / (60 * 60 * 24 * 1000) % 7);
|
||||||
|
|
||||||
return { days, hours, minutes, seconds };
|
return { days, hours, minutes, seconds };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function hydrateDropdown(
|
function hydrateDropdown(
|
||||||
root,
|
root,
|
||||||
dropdown,
|
dropdown,
|
||||||
show = d => d.toggleAttribute('hidden', false),
|
show = d => d.toggleAttribute('hidden', false),
|
||||||
hide = d => d.toggleAttribute('hidden', true)
|
hide = d => d.toggleAttribute('hidden', true)
|
||||||
) {
|
) {
|
||||||
|
|
||||||
function clickListener(e) {
|
function clickListener(e) {
|
||||||
show(dropdown);
|
show(dropdown);
|
||||||
root.removeEventListener('click', clickListener);
|
root.removeEventListener('click', clickListener);
|
||||||
const { right, bottom } = root.getBoundingClientRect();
|
const { right, bottom } = root.getBoundingClientRect();
|
||||||
const { width } = dropdown.getBoundingClientRect();
|
const { width } = dropdown.getBoundingClientRect();
|
||||||
dropdown.style.left = (right - width) + 'px';
|
dropdown.style.left = (right - width) + 'px';
|
||||||
dropdown.style.top = (5 + bottom) + 'px';
|
dropdown.style.top = (5 + bottom) + 'px';
|
||||||
function hide1(e) {
|
function hide1(e) {
|
||||||
document.removeEventListener('mousedown', hide1);
|
document.removeEventListener('mousedown', hide1);
|
||||||
function hide2(e) {
|
function hide2(e) {
|
||||||
document.removeEventListener('mousedown', hide1);
|
document.removeEventListener('mousedown', hide1);
|
||||||
document.removeEventListener('mouseup', hide2);
|
document.removeEventListener('mouseup', hide2);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
hide(dropdown);
|
hide(dropdown);
|
||||||
root.addEventListener('click', clickListener);
|
root.addEventListener('click', clickListener);
|
||||||
}, 50);
|
}, 50);
|
||||||
}
|
}
|
||||||
document.addEventListener('mouseup', hide2);
|
document.addEventListener('mouseup', hide2);
|
||||||
};
|
};
|
||||||
document.addEventListener('mousedown', hide1);
|
document.addEventListener('mousedown', hide1);
|
||||||
}
|
}
|
||||||
root.addEventListener('click', clickListener);
|
root.addEventListener('click', clickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user