Skip to content

Instantly share code, notes, and snippets.

@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 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 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: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 / 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
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 / main.py
Created October 30, 2019 17:25
Terminal progress bar with python
import time
import math
import os
rows, columns = os.popen('stty size', 'r').read().split()
# `[]` (2) + precent (5)
terminal_progress_fill = int(columns) - 7
current_progress = 0
while current_progress <= 100:
@titangene
titangene / main.js
Created October 27, 2019 03:58
Remove uncommonly used languages ​​from Google Translate in chrome extension
translateElement = document.getElementById('gtx-host');
translateContentElements = translateElement.shadowRoot.getElementById('bubble-content');
translateOptions = [...translateContentElements.querySelectorAll('option')];
languages = ['zh-CN', 'auto', 'en', 'ja'];
translateOptions.filter(option => !languages.includes(option.value))
.forEach(option => option.remove());
@titangene
titangene / main.js
Created October 27, 2019 03:55
Convert Notion's note title and URL to Markdown link format and copy to clipboard
urlIconSelector = 'path[d*="M3.73333,3.86667 L7.46667"]';
urlIcons = document.querySelectorAll(urlIconSelector);
blocks = Array.prototype.map.call(urlIcons, icon => {
urlTitleNode = icon.parentNode.parentNode.nextSibling;
if (urlTitleNode.textContent === 'URL') {
urlValueNode = urlTitleNode.parentNode.parentNode.parentNode.nextSibling;
if (urlValueNode.textContent[0] !== 'Empty')
return urlValueNode.querySelector('span');
@titangene
titangene / main.js
Last active March 11, 2024 04:00
copy YouTube subtitles
!(() => {
const captionElements = document.getElementsByClassName('segment-text style-scope ytd-transcript-segment-renderer');
const caption = [...captionElements]
.reduce((result, element) => result + element.innerText + ' ', '')
.replace(/[\.]/g, '.\n\n');
const textArea = document.createElement('textarea');
copyText = caption;
textArea.value = copyText;
document.body.appendChild(textArea);