Skip to content

Instantly share code, notes, and snippets.

@rishpandey
Last active August 26, 2021 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rishpandey/9eb6496564319166b939ff5a095011f2 to your computer and use it in GitHub Desktop.
Save rishpandey/9eb6496564319166b939ff5a095011f2 to your computer and use it in GitHub Desktop.
ConversionAI SEO TamperMonkey
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://app.jarvis.ai/docs/*
// @icon https://www.google.com/s2/favicons?domain=jarvis.ai
// @grant none
// ==/UserScript==
window.onload = setTimeout(function() {
const newDiv = document.createElement("div");
const editor =document.querySelector('.ql-editor')
newDiv.innerHTML = `<p>3-8 Keywords</p><textarea id="keyword-input" rows="4"></textarea><br/><div id="keyword-list"></div>`;
newDiv.style.position = 'absolute'
newDiv.style.top = '25%'
newDiv.style.width = '250px'
newDiv.style.right = '0'
newDiv.style.padding = '10px'
newDiv.style.background = '#cccccc'
newDiv.querySelector('textarea').style.width = "100%";
newDiv.querySelector('textarea').addEventListener('input', function(event){
rewriteKeywordList(event.target.value.split(','));
})
function rewriteKeywordList(tokens){
newDiv.querySelector('#keyword-list').innerHTML = '';
let ul = document.createElement("ul");
ul.style.listStyle = 'decimal'
ul.style.marginLeft = '15px'
let li = '';
tokens.forEach(t => {
if(t == '') return;
let count = getKeywordCount(t.trim());
let style = getStyleFromTokenCount(count);
li += "<li style='"+ style +"'>"+ t +" - ("+ count + "/" + Math.floor(totalEditorCount() / 200) +")</li>";
})
ul.innerHTML = li;
newDiv.querySelector('#keyword-list').appendChild(ul);
}
function getKeywordCount(token){
let regex = /(<([^>]+)>)/ig;
let text= editor.innerHTML.replace(regex, "");
return (text.match(new RegExp(token, "ig")) || []).length;
}
function totalEditorCount(){
let totalWordCountElement = document.querySelector("#app > div:nth-child(1) > div:nth-child(1) > div > div > div.fixed.inset-x-0.top-0.z-10.flex.items-center.h-12.px-2.space-x-2.bg-white.border-b.border-gray-200.dark\\:border-gray-700.dark\\:bg-gray-800 > div.pr-2.text-sm.text-gray-400");
return totalWordCountElement ? totalWordCountElement.innerHTML.replaceAll(/[^0-9]/g, "") : 0;
}
function getStyleFromTokenCount(count){
if(count === 0) return 'color:red';
let totalCount = totalEditorCount();
if(totalCount === 0){
if(count > 5) return 'color:green';
return 'color:orange';
}
let shouldAppear = Math.floor(totalCount / 200);
if(count > shouldAppear) return 'color:darkred;text-decoration: line-through;';
if(count = shouldAppear) return 'color:green';
return 'color:orange';
}
editor.addEventListener('input',function(e){
let tokens = newDiv.querySelector('textarea').value.split(',')
rewriteKeywordList(tokens)
})
document.body.appendChild(newDiv);
}, 10000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment