Loading...
More JavaScript Posts
import { configureStore } from "@reduxjs/toolkit";import { combineReducers } from "redux";import profile from "./profile";import auth from "./auth";import alert from "./alert";const reducer = combineReducers({profile,auth,alert,});const store = configureStore({ reducer });export default store;
//Allegedly never tested on the twitter websitefunction scrapeScreen(){let articles = Array.from(document.getElementsByTagName("article"));let results = [];for(let tweet of articles){const isAnAd = Array.from(tweet.querySelectorAll("span")).map((e)=>e.textContent).includes("Ad");if(isAnAd){//console.log(tweet, "is an ad. Skipping...");continue;}const userName = tweet.querySelector("[data-testid='User-Name'] > div:nth-child(2) > div > div")?.textContent;const tweetContent = tweet.querySelector("[data-testid='tweetText']")?.textContent;const timeStamp = tweet.querySelector("time")?.getAttribute("datetime");const tweetLink = tweet.querySelector("time")?.parentElement?.getAttribute("href");if((!userName) || (!tweetContent)) continue;results.push({username: userName,tweetText: tweetContent,timeStamp: timeStamp,tweetLink: tweetLink});}return results;}let scraped = scrapeScreen();setInterval(()=>{scraped = scraped.concat(scrapeScreen().filter((tweet)=>{for(let scrapedTweet of scraped){if(scrapedTweet.username == tweet.username && scrapedTweet.tweetText == tweet.tweetText) return false;}return true;}));}, 500); //Scrape everything on the screen twice a secondwindow.scrollIntervalId = setInterval(function(){window.scrollBy(0, 1000);}, 500); //Scroll for me//http://bgrins.github.io/devtools-snippets/#console-save(function(console){console.save = function(data, filename){if(!data) {console.error('Console.save: No data')return;}if(!filename) filename = 'console.json'if(typeof data === "object"){data = JSON.stringify(data, undefined, '\t')}var blob = new Blob([data], {type: 'text/json'}),e = document.createEvent('MouseEvents'),a = document.createElement('a')a.download = filenamea.href = window.URL.createObjectURL(blob)a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)a.dispatchEvent(e)}})(console)setTimeout(()=>{clearTimeout(window.scrollIntervalId);delete window.scrollIntervalId;console.save(scraped, "TwitterScrape" + Date.now() + ".json");}, 60 * 1000 * 20); //Twenty minutes
function printHeap(heap, index, level) {if (index >= heap.length) {return;}console.log(" ".repeat(level) + heap[index]);printHeap(heap, 2 * index + 1, level + 1);printHeap(heap, 2 * index + 2, level + 1);}//You can call this function by passing in the heap array and the index of the root node, which is typically 0, and level = 0.let heap = [3, 8, 7, 15, 17, 30, 35, 2, 4, 5, 9];printHeap(heap,0,0)
function formatDate(date) {return date.toLocaleDateString();}function Comment(props) {return (<div className="Comment"><div className="UserInfo"><imgclassName="Avatar"src={props.author.avatarUrl}alt={props.author.name}/><div className="UserInfo-name">{props.author.name}</div></div><div className="Comment-text">{props.text}</div><div className="Comment-date">{formatDate(props.date)}</div></div>);}const comment = {date: new Date(),text: 'I hope you enjoy learning React!',author: {name: 'Hello Kitty',avatarUrl: 'https://placekitten.com/g/64/64',},};ReactDOM.render(<Commentdate={comment.date}text={comment.text}author={comment.author}/>,document.getElementById('root'));
// Get the text that the user has selectedconst getSelectedText = () => window.getSelection().toString();getSelectedText();
const jwt = require("jsonwebtoken");const authToken = (req, res, next) => {const token = req.headers["x-auth-token"];try {req.user = jwt.verify(token, process.env.ACCESS_TOKEN_SECRET);next();} catch (err) {console.log(err.message);res.status(401).json({ msg: "Error authenticating token" });}};module.exports = authToken;