Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 95 additions & 1 deletion contentScript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
// const btn=document.getElementById("segmented-like-button")
// global url
let globalURL;

const globalURLSetter = () =>{
globalURL=window.location.href.split(".com")[0]+".com/";
console.log(globalURL)
}
globalURLSetter();



const newYoutubeProfileLoaded = () => {
const youtubeBtnControls = document.querySelector(
Expand Down Expand Up @@ -54,6 +63,91 @@ const newVideLoaded = () => {
};


const innerChildFinder = (ele) =>{
let textParent=null;
let elee=ele;

while((elee.firstChild)!==null){
textParent=elee;
elee=elee.firstChild;
}
return textParent
}

// Input Event Fire
// 1.Twitter
const twittInputHandler = (ele,textToBeReplaced) =>{
let textParent=innerChildFinder(ele);
const wrapper = textParent?.parentNode;
textParent.innerText = textToBeReplaced
console.log(textParent)
wrapper.innerHTML = textParent.innerHTML
wrapper.dispatchEvent(new Event("input",{'bubbles':true,cancelable:"true"}));
}
// 2.LinkedIn
const linkedinInputHandler = (ele,textToBeReplaced) => {
const wrapper = ele;
wrapper.innerHTML = `<p>${textToBeReplaced}</p>`
wrapper.dispatchEvent(new Event("input",{'bubbles':true,cancelable:"true"}))
}


// 3. Youtube
const youtubeHandler = (ele,textToBeReplaced) => {
console.log(ele)
if(ele.tagName === "INPUT" )ele.value=textToBeReplaced;
else{
const textParent = innerChildFinder(ele);
textParent.innerText = textToBeReplaced;
}
}


// 4. GitHub
const gitHubHandler = (ele,textToBeReplaced) => {
ele.value=textToBeReplaced
}




// Genral function

// const commandReplacer = (ele,textToBeReplaced) =>{
// let textParent=innerChildFinder(ele);
// const wrapper = textParent?.parentNode;
// textParent.innerText = textToBeReplaced
// const div = document.createElement("div");
// div.appendChild(textParent);
// console.log(div.innerHTML)
// wrapper.innerHTML = div.innerHTML;
// console.log(wrapper);
// wrapper.dispatchEvent(new Event("input",{'bubbles':true,cancelable:true}));
// }

const urlToFunctionMapper = {
"https://www.linkedin.com/" : linkedinInputHandler,
"https://twitter.com/" : twittInputHandler,
"https://www.youtube.com/" : youtubeHandler,
"https://github.com/":gitHubHandler,
}


window.onkeyup=(e)=>{
// Genral way to grab the text from a element
console.log(e.target.innerText);
let command = e.target.value || e.target.innerText;
//Command check
console.log(command)
if(command.includes("/share")){
console.log("hello")
// api call to our API to get the result accoding to the command
const funct=urlToFunctionMapper[globalURL];
// commandReplacer(e.target,"Share twitt");
funct(e.target,"Example")
}
}


// Message Listers
chrome.runtime.onMessage.addListener((obj, sender, response) => {
Expand Down
6 changes: 3 additions & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "0.1.0",
"description": "More than A Bookmark",
"permissions": ["storage", "tabs","scripting","activeTab"],
"host_permissions": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*"],
"host_permissions": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*","https://discord.com/*","https://github.com/*","https://web.whatsapp.com/"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*"],
"matches": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*","https://discord.com/*","https://github.com/*","https://web.whatsapp.com/"],
"js": ["contentScript.js"]
}
],
Expand All @@ -18,7 +18,7 @@
"resources": [
"assets/bookmark.png"
],
"matches": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*"]
"matches": ["https://*.youtube.com/*","https://*.twitter.com/*","https://*.linkedin.com/*","https://discord.com/*","https://github.com/*","https://web.whatsapp.com/*"]
}
],
"action": {
Expand Down