Java script custom site search window for a science project

I am writing a paper which is about fake news as a sociolinguistic phenomenon and I thought it might be a good idea to make a chrome extension that would search a phrase on a sit that you want. I've already made an HMLT google search, but I thought it would be nice to make like a custom site search like BBC, but I can't seem to figure out the code for that. I've tried to rewrite it in 4 different ways, I got pissed and looked up some code online to inspire but it doesn't work either. Maybe there's another error. I'm just 6 months into programming so if you could give me some insights how to fix this, I'd really appreciate this

console.log("Fake Reader by Mateusz Moćko Ready To GO!");

let BBCUrl = "";
let BBCUrl1 = "&page=1";
function updateURL(buttonSelector) {
  const text = $(buttonSelector).text().slice(0, -1);
  if ($(buttonSelector).hasClass("selected")) {
    if (!BBCUrl.includes(text)) {
      /(=)$/.test(BBCUrl) ? (BBCUrl += text) : (BBCUrl += "," + text);
  } else {
    if (BBCUrl.includes(text)) {
      BBCUrl = BBCUrl.replace(text, "" + BBCUrl1);
    } else if (BBCUrl.includes("," + text + BBCUrl1)) {
      BBCUrl = BBCUrl.replace("," + text, "" + BBCUrl);
  $(".ecmt-button").attr("href", BBCUrl);

That is the .js file, below is manifest.json:

  "manifest_version": 2,
  "name": "Fake Reader",
  "version": "0.4",
  "content_scripts": [
      "matches": ["<all_urls>"],
      "js": ["fakereader.js"],
      "css": ["popupwindow/style.css"]
  "permissions": ["tabs", "contextMenus"],
  "description": "Extension to detect fake news stories",
  "browser_action": {
    "default_icon": "fake.png",
    "default_popup": "popupwindow/index.html",
    "default_title": "Check if your phrase is fake news."
  "icons": {
    "16": "FAKENEWS.png",
    "32": "FAKENEWS.png",
    "48": "FAKENEWS.png",
    "128": "FAKENEWS.png"
  "background": {
    "page": "popupwindow/index.html"

Read more here:

Content Attribution

This content was originally published by matxi at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: