diff --git a/contentScript.js b/contentScript.js index a0a6aba..da7da88 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,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 = `

${textToBeReplaced}

` + 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) => { 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": {