Skip to content

Instantly share code, notes, and snippets.

@titangene
titangene / main.js
Created June 7, 2023 15:13
Switch Pluralsight Subtitle (EN <--> TW)
(() => {
class ButtonElement {
constructor(selector) {
this.selector = selector;
}
get element() {
return document.querySelector(this.selector);
}
@titangene
titangene / main.js
Last active July 14, 2023 15:05
Convert chrome tab link to footnote link format and copy
(function() {
class MarkdownSyntax {
static getFootNote({ identifier, content }) {
return `${identifier}: ${content}`;
}
static getLink({ title, url }) {
return `[${title}](${url})`;
}
}
@titangene
titangene / main.js
Last active June 28, 2023 06:59
copy YouTube song title
(() => {
const videoDescriptionSelector = '#description-inline-expander > yt-attributed-string';
const $videoDescription = document.querySelector(videoDescriptionSelector);
const [songTitle, artist] = $videoDescription?.textContent
.split('\n\n')[1]
.split(' · ');
const fullArtist = document.querySelector('#owner #upload-info a').textContent;
const result = `${fullArtist} - ${songTitle}`;
copy(result);
@titangene
titangene / main.js
Last active February 22, 2024 01:30
redirect Facebook, YouTube, GitHub, Medium
(() => {
const redirectMatchers = [
{
matcher: () => location.host.includes('slideshare.net'),
action: redirectSlideShare
},
{
matcher: () => location.host.includes('facebook'),
action: redirectFacebook
},
@titangene
titangene / main.js
Last active December 2, 2022 00:23
redirect Facebook mobile page <---> desktop page
(() => {
if (location.host === 'm.facebook.com') {
location.href = 'https://www.facebook.com' + location.pathname + location.search;
return;
}
if (location.host === 'www.facebook.com') {
location.href = 'https://m.facebook.com' + location.pathname + location.search;
return;
}
})();
@titangene
titangene / main.js
Last active August 13, 2023 01:42
document sidebar toggle (support Vue docs, React docs, TS docs, BootstrapVue docs, MDN docs, GitHub Repo)
(function() {
class Sidebar {
constructor(element) {
this.element = element;
}
get display() {
return this.element.style.display;
}
@titangene
titangene / main.js
Created June 24, 2022 11:24
YouTube Shorts redirect to normal vedio page
(() => {
const vedioId = location.pathname.split('/').at(-1);
location.href = `${location.origin}/watch?v=${vedioId}`;
})();
@titangene
titangene / main.js
Created June 5, 2022 15:20
TypeScript document sidebar toggle
(function() {
const sidebar = document.querySelector('#sidebar');
sidebar.style.display = !sidebar.style.display ? 'none' : null;
})()
@titangene
titangene / main.js
Last active July 31, 2022 09:59
copy spotify music title & artists
(() => {
const title = document.querySelector('[data-testid=context-item-info-title]').textContent;
const [...artists] = document.querySelectorAll('[data-testid=context-item-info-artist]');
const artistList = artists.map(artist => artist.textContent).join(' & ');
const textArea = document.createElement('textarea');
textArea.value = `${artistList} - ${title}`;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('Copy');
@titangene
titangene / main.js
Last active December 2, 2022 00:14
redirect GitHub page <---> GitHub repo page
(() => {
if (location.hostname === 'github.com') {
const [_, username, repo] = location.pathname.split('/');
location.href = `https://${username}.github.io/${repo}`;
return;
}
if (location.hostname.includes('github.io')) {
const username = location.host.split('.')[0];
const repo = location.pathname.split('/')[1];
location.href = `https://github.com/${username}/${repo}`;