Skip to content

Instantly share code, notes, and snippets.

View prateek3255's full-sized avatar
🔭
A young jedi in a galaxy far far away

Prateek Surana prateek3255

🔭
A young jedi in a galaxy far far away
View GitHub Profile
document.addEventListener("DOMContentLoaded", function() {
let devfolioOptions = {
buttonSelector: "#devfolio-apply-now",
key: "tezindia-harappa"
};
let script = document.createElement("script");
script.src = "https://devfolio.surge.sh/applynow.min.js";
document.head.append(script);
function replaceText(find, replace){
const regex = new RegExp(find, "gi");
const contents = document.querySelectorAll('p,li,span,h1,h2,h3,h4,h5,h6');
for(const snippet of contents){
snippet.textContent = snippet.textContent.replace(regex, replace);
}
}
chrome.runtime.onMessage.addListener(function(message){
if(message.action === 'REPLACE_TEXT'){
replaceText(message.find, message.replace);
const replacelyForm = document.getElementById("replacely-form");
const searchText = document.getElementById("search");
const replaceText = document.getElementById("replace");
replacelyForm.onsubmit = function(e){
e.preventDefault();
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {action: "REPLACE_TEXT", find: searchText.value, replace: replaceText.value});
window.close();
});
}
<!DOCTYPE html>
<html>
<head>
<link rel = "stylesheet"
type = "text/css"
href = "popup.css" />
</head>
<body>
<div class="wrap">
<h1>Replacely</h1>
function replaceText(){
const FIND = "the";
const REPLACE_WITH = "replacely";
const regex = new RegExp(FIND, "gi");
const contents = document.querySelectorAll('p,li,span,h1,h2,h3,h4,h5,h6');
for(const snippet of contents){
snippet.textContent = snippet.textContent.replace(regex, REPLACE_WITH);
}
}
chrome.runtime.onMessage.addListener(function(message){
const iconRules = [{
conditions: [
new chrome.declarativeContent.PageStateMatcher({
pageUrl: {hostEquals: 'medium.com'},
})
],
actions: [new chrome.declarativeContent.ShowPageAction()]
}];
chrome.declarativeContent.onPageChanged.removeRules(undefined, function() {
chrome.declarativeContent.onPageChanged.addRules(iconRules);
const FIND = "the";
const REPLACE_WITH = "replacely";
const regex = new RegExp(FIND, "gi");
const contents = document.querySelectorAll('p,li,span,h1,h2,h3,h4,h5,h6');
for(const snippet of contents){
snippet.textContent = snippet.textContent.replace(regex, REPLACE_WITH);
}
{
"name": "Replacely",
.
.
.
"content_scripts": [
{
"matches": ["https://medium.com/*"],
"js": ["contentScript.js"]
}
{
"name": "Replacely",
"version": "0.1",
"description": "An extension to replace text in medium articles",
"manifest_version": 2,
"page_action": {
"default_icon": {
"16": "images/replacely16.png",
"32": "images/replacely32.png",
"48": "images/replacely48.png",
{
"name": "Replacely",
"version": "0.1",
"description": "An extension to replace text in medium articles",
"manifest_version": 2,
"page_action": {
"default_icon": {
"16": "images/replacely16.png",
"32": "images/replacely32.png",
"48": "images/replacely48.png",