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 data = [ | |
| { "name": "John", "time": new Date().toISOString(), "age": "old" }, | |
| { | |
| "name": "Jeff", "time": new Date().toISOString(), "age": "older" | |
| } | |
| ] | |
| const header = Object.keys(data[0]).map(_ => JSON.stringify(_)).join(';') + '\n' | |
| const outData = data.reduce((acc, row) => { | |
| return acc + Object.values(row).map(_ => JSON.stringify(_)).join(';') + '\n' |
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
| // Inspired by https://towardsdatascience.com/quickly-extract-all-links-from-a-web-page-using-javascript-and-the-browser-console-49bb6f48127b | |
| var atags = document.querySelectorAll("a"); | |
| let links = []; | |
| let hashes = {}; | |
| for await (atag of atags){ | |
| var anchor = atag.textContent.replace(/\s+/g, ' ').trim(); | |
| var link = atag.href.replace(/\/$/, ""); // remove trailing slash | |
| var rel = atag.rel; | |
| var hash = md5(link) |
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
| let url = "https://test.com/現役軍人轉公職-警察有哪些方法-補助5萬如何申請-4db7c0fd81b0" | |
| const english = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?^[ -~]+$/; | |
| if (english.test(url)) { | |
| console.log("URL IS ENGLISH-most likely") | |
| } |
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 myurl = "journey?reference=123&line=A&destination=China&operator=Belbo&departure=1043&vehicle=ARC"; | |
| var keyval = myurl.split('?')[1].split('&'); | |
| for(var x=0,y=keyval.length; x<y; x+=1) | |
| console.log(keyval[x], keyval[x].split('=')[0], keyval[x].split('=')[1]); | |
| /* | |
| reference=123 reference 123 | |
| line=A line A | |
| destination=China destination China | |
| operator=Belbo operator Belbo |
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
| let url = "https://www.amazon.com/SanDisk-128GB-microSDXC-Memory-Adapter/dp/B073JYC4XM/"; | |
| let kwparse = (url.replace('https://','').replace('http://','').replace('www','').replace('com','').split('-').join().split('/').join().split('.')).join(',').replace(/^,/, '') | |
| let kwuniq = [...new Set(kwparse.split(','))].filter(function(e){return e}); | |
| console.log(kwuniq) | |
| // ["amazon", "SanDisk", "128GB", "microSDXC", "Memory", "Adapter", "dp", "B073JYC4XM"] | |
| // Hat Tip - Find a cleaner version at https://gist.github.com/dsottimano/52060e6a43d96804f33c59366c472305 |
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
| <!-- JUST ADD JS --> | |
| <html> | |
| <head> | |
| <style> | |
| /*! CSS Used from: https://fonts.googleapis.com/css?family=Google+Sans:400,500|Roboto:400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700|Material+Icons */ | |
| .material-icons{font-family:'Material Icons';font-weight:normal;font-style:normal;font-size:24px;line-height:1;letter-spacing:normal;text-transform:none;display:inline-block;white-space:nowrap;word-wrap:normal;direction:ltr;-webkit-font-feature-settings:'liga';-webkit-font-smoothing:antialiased;} | |
| /*! CSS Used from: https://www.gstatic.com/devrel-devsite/prod/v4d5d232859440be8edf63a1095b80ebe5c19605e99f3b348a30c4b0140c2eb88/cloud/css/app.css */ | |
| devsite-code{clear:both;direction:ltr!important;display:block;margin:16px 0;overflow:hidden;position:relative;} | |
| devsite-code .devsite-code-buttons-container{position:absolute;right:0;top:0;} | |
| devsite-code .devsite-code-buttons-container button{-webkit-box-align:center;-webkit-align-items:center;align-items:center;background:0;border:0;-webkit-border-radius |
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(console){ | |
| console.save = function(data, filename){ | |
| if(!data) { | |
| console.error('Console.save: No data') | |
| return; | |
| } | |
| if(!filename) filename = 'console.json' |
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 h1s = await page.evaluate( | |
| () => [...document.querySelectorAll('h1')].map(elem => elem.innerText.trim())) | |
| const h2s = await page.evaluate( | |
| () => [...document.querySelectorAll('h2')].map(elem => elem.innerText.trim())) | |
| const h3s = await page.evaluate( | |
| () => [...document.querySelectorAll('h3')].map(elem => elem.innerText.trim())) | |
| const h4s = await page.evaluate( | |
| () => [...document.querySelectorAll('h4')].map(elem => elem.innerText.trim())) | |
| const h5s = await page.evaluate( | |
| () => [...document.querySelectorAll('h5')].map(elem => elem.innerText.trim())) |
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 getHostName(url) { | |
| var match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i); | |
| if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) { | |
| return match[2]; | |
| } | |
| else { | |
| return null; | |
| } | |
| } |
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 utcSeconds = 1234567890; | |
| var d = new Date(0); // The 0 there is the key, which sets the date to the epoch | |
| d.setUTCSeconds(utcSeconds); |