close
Jump to content

User:Ca/RSNsearch.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//written by ChatGPT
function openRSNSearchBox() {
  $('body').prepend('<div id="rsn-modal">' +
    '<div id="rsn-content">' +
      '<h2>RSN Search</h2>' +
      '<p>Search for topics on the Reliable Sources Noticeboard</p>' +
      '<input type="text" id="rsn-input" placeholder="Enter search query">' +
      '<a id="rsn-link" href="#" target="_blank">Search</a>' +
      '<button id="rsn-close">&#10006;</button>' +
    '</div>' +
  '</div>');

  $("#rsn-modal").css({
    "position": "fixed",
    "z-index": "1",
    "left": "0",
    "top": "0",
    "width": "100%",
    "height": "100%",
    "overflow": "hidden",
    "background-color": "rgba(0, 0, 0, 0.4)"
  });

  $("#rsn-content").css({
    "background-color": "#ffffff",
    "margin": "15% auto",
    "padding": "20px",
    "border": "1px solid #ccc",
    "width": "400px",
    "font-size": "16px",
    "box-shadow": "0px 2px 8px rgba(0, 0, 0, 0.2)",
    "border-radius": "4px",
    "text-align": "center",
    "position": "relative"  // Added relative position for #rsn-content
  });

  $("#rsn-close").css({
    "position": "absolute", // Absolute positioning inside #rsn-content
    "top": "10px",
    "right": "10px",
    "border": "none",
    "background-color": "transparent",
    "font-size": "24px",
    "cursor": "pointer",
    "outline": "none"
  });

  $("#rsn-close").click(function() {
    $("#rsn-modal").remove();
  });

  $("#rsn-input").on("input", function() {
    var inputValue = $(this).val();
    var searchLink = "https://en.wikipedia.org/w/index.php?search=" + inputValue + "&prefix=Wikipedia%3AReliable+sources%2FNoticeboard&title=Special:Search&profile=advanced&fulltext=1&ns0=1";
    $("#rsn-link").attr("href", searchLink);
  });
}

$(document).ready(function() {
  mw.util.addPortletLink('p-tb', 'javascript:void(0)', 'RSN Search', 'rsn-search-link', null, null);

  $('#rsn-search-link').on('click', function() {
    openRSNSearchBox();
  });
});