From 4bec64575899e094f2042f56fdeb81def9bde273 Mon Sep 17 00:00:00 2001 From: subhradwi01 Date: Sat, 25 Mar 2023 21:08:43 +0530 Subject: [PATCH 1/2] Input handler created --- contentScript.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/contentScript.js b/contentScript.js index a0a6aba..959e9d0 100644 --- a/contentScript.js +++ b/contentScript.js @@ -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( @@ -54,6 +63,48 @@ const newVideLoaded = () => { }; +// Input Event Fire +// 1.Twitter +const twittInputHandler = (ele,textToBeReplaced) =>{; + const wrapper = ele.querySelector('[data-text="true"]')?.parentNode; + wrapper.innerHTML = `${textToBeReplaced}` + wrapper.dispatchEvent(new Event("input",{'bubbles':true,cancelable:"true"})); +} + +// 2.LinkedIn +const linkedinInputHandler = (ele,textToBeReplaced) => { + const wrapper = ele; + wrapper.innerHTML = `

${textToBeReplaced}

` + wrapper.dispatchEvent(new Event("input",{'bubbles':true,cancelable:"true"})) +} + + +// 3. Youtube +const youtubeHandler = (ele,textToBeReplaced) => { + ele.value=textToBeReplaced; +} + + +// Genral function + +const urlToFunctionMapper = { + "https://www.linkedin.com/" : linkedinInputHandler, + "https://twitter.com/" : twittInputHandler, + "https://www.youtube.com/" : youtubeHandler, +} + + +window.onkeyup=(e)=>{ + // Genral way to grab the text from a element + let command = e.target.value || e.target.innerText; + //Command check + if(command === "/share"){ + // api call to our API to get the result accoding to the command + const funct=urlToFunctionMapper[globalURL]; + funct(e.target,"Share twitt"); + } +} + // Message Listers chrome.runtime.onMessage.addListener((obj, sender, response) => { From 6c8bd5b8e16b152802e6ab843c4a92fa13e2ccfa Mon Sep 17 00:00:00 2001 From: subhradwi01 Date: Sun, 26 Mar 2023 01:28:39 +0530 Subject: [PATCH 2/2] github and youtube comment fixed --- contentScript.js | 57 ++++++++++++++++++++++++++++++++++++++++++------ manifest.json | 6 ++--- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/contentScript.js b/contentScript.js index 959e9d0..da7da88 100644 --- a/contentScript.js +++ b/contentScript.js @@ -63,14 +63,27 @@ 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) =>{; - const wrapper = ele.querySelector('[data-text="true"]')?.parentNode; - wrapper.innerHTML = `${textToBeReplaced}` +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; @@ -81,27 +94,57 @@ const linkedinInputHandler = (ele,textToBeReplaced) => { // 3. Youtube const youtubeHandler = (ele,textToBeReplaced) => { - ele.value=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 - if(command === "/share"){ + 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]; - funct(e.target,"Share twitt"); + // commandReplacer(e.target,"Share twitt"); + funct(e.target,"Example") } } diff --git a/manifest.json b/manifest.json index acfb3f3..a48e1d4 100644 --- a/manifest.json +++ b/manifest.json @@ -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"] } ], @@ -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": {