Last active
March 10, 2022 02:52
-
-
Save paulcoding810/f3f7ceba5efb0bdf082785b92fbab8f3 to your computer and use it in GitHub Desktop.
some js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("hello world") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var o = { | |
foo: "bar", | |
arr: [1, "hidf", { | |
asd: "hidf" | |
}], | |
subo: { | |
foo2: "bar2",foo3:{ | |
te:"hiho" | |
} | |
}, | |
hiheheh: { | |
foo2: "hiasdf" | |
} | |
}; | |
// https://stackoverflow.com/questions/13594241/how-to-split-string-between-two-separators-in-javascript | |
// o=JSON.parse(document.getElementById("initial-state").innerText) | |
var getValue = (o, trace) => trace.reduce((r, k) => r[k], o); | |
function traverse(obj, value, path="",trace=[]) { | |
let last = path | |
let lastTrace=Array.from(trace) | |
for (let i in obj) { | |
trace = Array.from(lastTrace) | |
if (Array.isArray(obj)){ | |
path = last + `[${i}]`; | |
trace.push( parseInt(i)) | |
} | |
else{ | |
path = last + `["${i}"]`; | |
trace.push(`${i}`) | |
} | |
if (String(i).match(value)){ | |
console.log(path) | |
console.log(getValue(o,trace)) | |
// console.log("%c"+getValue(o,trace), "color:red") | |
} | |
if (typeof (obj[i]) == "string") { | |
if (String(obj[i]).match(value)) { | |
console.log(path) | |
console.log(getValue(o,trace)) | |
// console.log("%c"+getValue(o,trace), "color:red") | |
} | |
} | |
if (obj[i] !== null && typeof (obj[i]) == "object") { | |
traverse(obj[i], value, path,trace); | |
} | |
} | |
} | |
traverse(o, "hi" ,"o",[]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sayHi(){ | |
console.log("Hi 123") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const videoUrls = ytplayer.config.args.adaptive_fmts | |
.split(',') | |
.map(item => item | |
.split('&') | |
.reduce((prev, curr) => (curr = curr.split('='), | |
Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])}) | |
), {}) | |
) | |
.reduce((prev, curr) => Object.assign(prev, { | |
[curr.quality_label || curr.type]: curr | |
}), {}); | |
console.log(videoUrls); | |
// ES5 version | |
var videoUrls = ytplayer.config.args.adaptive_fmts | |
.split(',') | |
.map(function (item) { | |
return item | |
.split('&') | |
.reduce(function (prev, curr) { | |
curr = curr.split('='); | |
return Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])}) | |
}, {}); | |
}) | |
.reduce(function (prev, curr) { | |
return Object.assign(prev, { | |
[curr.quality_label || curr.type]: curr | |
}); | |
}, {}); | |
console.log(videoUrls); | |
//window notification | |
Notification.requestPermission(function (permission) { | |
// If the user accepts, let's create a notification | |
if (permission === "granted") { | |
var notification = new Notification("Hi there!"); | |
} | |
}); | |
//copy window document selection | |
document.getSelection().toString() | |
. | |
//fast function execution | |
(function(a,b){return a+b;}(1,2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment