Skip to content

Instantly share code, notes, and snippets.

@titangene
titangene / main.js
Last active July 31, 2022 10:02
Bootstrap doc TW / EN switch
(function() {
if (location.host.includes('bootstrap.hexschool'))
url = `https://getbootstrap.com${location.pathname.replace('4.2', '4.6')}`;
else if (location.host.includes('bootstrap5.hexschool'))
url = `https://getbootstrap.com${location.pathname.replace('5.0', '5.0')}`;
else if (location.host.includes('getbootstrap')) {
if (location.pathname.includes('5.0')) {
url = `https://bootstrap5.hexschool.com${location.pathname.replace('5.0', '5.0')}`;
@titangene
titangene / settings.json
Created August 29, 2020 15:44
newtongwen-settings
{
"version": "",
"autoConvert": "trad",
"iconAction": "trad",
"symConvert": false,
"inputConvert": "none",
"fontCustom": {
"enable": false,
"trad": "微軟正黑體, PMingLiU, MingLiU, 新細明體, 細明體",
"simp": "MS Song, 宋体, SimSun"
@titangene
titangene / main.js
Last active July 31, 2022 10:02
Vue 3 document sidebar toggle
(function() {
const sidebar = document.querySelector('.sidebar');
const page = document.querySelector('.page');
const main = document.querySelector('main');
if (!sidebar.style.display) {
sidebar.style.display = 'none';
if (location.host === 'next.router.vuejs.org') {
page.style.margin = '0';
@titangene
titangene / main.js
Last active December 10, 2022 12:07
複製 Google Maps 地點的營業時間
(() => {
const weekList = { '一': 0, '二': 1, '三': 2, '四': 3, '五': 4, '六': 5, '日': 6 };
const result = document.querySelector('[role="region"] .fontBodyMedium > [role="button"] + [aria-label]')
.getAttribute('aria-label')
.replace('. 隱藏本週營業時間', '')
.split('; ')
.map(item => {
const [fullWeek, ...openHours] = item.split('、');
return {
week: fullWeek[2],
@titangene
titangene / main.js
Last active July 31, 2022 10:01
inject dayjs
(async () => {
async function appendScript(url) {
return new Promise(resolve => {
const script = document.createElement('script');
script.setAttribute('src', url);
script.addEventListener("load", resolve);
document.body.appendChild(script);
});
}
async function loadPlugin(pluginName) {
@titangene
titangene / main.js
Last active September 3, 2022 08:56
Google translate 文字不換行
(() => {
const inlineCodePattern = /(\w+\.)*\w+\(\)/g;
function formatParagraph(paragraph) {
const lines = paragraph.split('\n');
return formatLines(lines);
}
function formatLines(lines) {
const result = lines
@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}`;
@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
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
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}`;
})();