Skip to content

Instantly share code, notes, and snippets.

@andersonbosa
Created November 28, 2020 13:10
Show Gist options
  • Save andersonbosa/6c47c3cc0a7bde15bf4a0b7fa4bf6e06 to your computer and use it in GitHub Desktop.
Save andersonbosa/6c47c3cc0a7bde15bf4a0b7fa4bf6e06 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Dicio.com.br popup
// @namespace Violentmonkey Scripts
// @grant none
// @version 1.0
// @author -
// @description 11/28/2020, 10:08:13 AM
// ==/UserScript==
// plugin idea
// when user click 2 times in same target
// try get word value from target
// request definition from dictionary site
// create pop-up with its definition
/**
* Get word definition from `//dicio.com.br/`
*
* @param {string} word
* @return {string}
*/
async function getWordDefinition (word) {
// todo: sanitize word
requestSettings = {
"headers": {
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"accept-language": "en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7",
"cache-control": "max-age=0",
"sec-fetch-dest": "document",
"sec-fetch-mode": "navigate",
"sec-fetch-site": "none", // cross-site
"sec-fetch-user": "?1",
"upgrade-insecure-requests": "0"
},
"method": "GET",
"mode": "cors"
}
return await fetch(`//www.dicio.com.br/${word}`, requestSettings)
.then(resp => resp)
}
console.log(getWordDefinition('prodigo'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment