Skip to content

Instantly share code, notes, and snippets.

@rockonyu
rockonyu / 書籤幫你唸.js
Last active March 17, 2022 08:17
將程式碼加入書籤,可以唸出當前滑鼠選擇的文字。
javascript: (() => {
const synth = window.speechSynthesis;
if (synth.speaking) {
synth.cancel();
return;
}
const selectedText = window.getSelection().toString();
if (!selectedText) {
return;
const withLoading = <P extends object>(
Component: React.ComponentType<P>
): React.FC<P & WithLoadingProps> => ({
loading,
...props
}: WithLoadingProps) =>
loading ? <LoadingSpinner /> : <Component {...props as P} />;
@rockonyu
rockonyu / styles.css
Created July 13, 2020 10:20
在 iOS 的 safari 套用 100vh
// ref: https://css-tricks.com/css-fix-for-100vh-in-mobile-webkit/
body {
min-height: 100vh;
min-height: -webkit-fill-available;
}
html {
height: -webkit-fill-available;
}
var getDecimalValue = function(head) {
const items = [];
let currentHead = head;
while(currentHead !== null) {
items.push(currentHead.val);
currentHead = currentHead.next;
}
let sum = 0;
@rockonyu
rockonyu / index.html
Created September 5, 2018 09:09
React & AngularJS
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body ng-app="todoApp">
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>
// 數字 X 左邊補零至 N 位數
// ex. X = 23, N = 4
("0000" + 23).slice(-4) // "0023"