commit c28af20e9cf398f4b0b4d835341bc19e3b6a371c Author: H. Saw Date: Sun Oct 1 10:45:02 2023 +0000 Upload files to "/" Added initial code. diff --git a/popup.js b/popup.js new file mode 100644 index 0000000..73a8eb7 --- /dev/null +++ b/popup.js @@ -0,0 +1,82 @@ +/* Popup Window Applet for Chrome + buzzcode2007 +*/ + +var popup_window = {}; + +function main() { + update_config(); + start_browse(); +}; + +function display_error(message, critical) { + /* Display an error message. + Returns: user's selection + */ + + if (critical) { + alert(message); + return(false); + } else { + var user_selection = confirm(message); + return(user_selection); + }; +} + +function update_config() { + /* Updates parameters. */ + var params = `scrollbars=no, status=no, location=no, toolbar=no, menubar=no`; + popup_window[`parameters`] = params; +}; + +function request_URL() { + /* Request for the URL, and check if it is valid. + + Returns: bool on navigation status */ + while (true) { + var user_navigate_URL = String(prompt(`Input a URL of another website or of a page within.`)).trim(); + + var check_URL = urlString=> { + var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol + '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name + '((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address + '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path + '(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string + '(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator + return !!urlPattern.test(urlString); + } + var user_navigate_URL_valid = check_URL(user_navigate_URL); + + if (user_navigate_URL_valid) {popup_window[`URL`] = user_navigate_URL; return(true);} + else if (!(user_navigate_URL)) {return (false);}; + }; +}; + +function display_URL(URL) { + /* Display the URL in a pop-up. + Returns: pop-up display status + */ + while (true) { + var popup_window_instance = {} + popup_window_instance[`status`] = window.open(URL, URL, popup_window[`parameters`]); + + if (!(popup_window_instance[`status`])) { + if (!(display_error(`The pop-up has been blocked! \nTo continue, try un-blocking it first for this site. `))) { + return (false); break; + }; + } else { + return(true); + }; + }; +}; + + +function start_browse() { + user_browse_confirm = request_URL(); + + if (user_browse_confirm) { + display_URL(popup_window[`URL`]); + }; +}; + +main(); \ No newline at end of file diff --git a/popup.min.js b/popup.min.js new file mode 100644 index 0000000..94a45d6 --- /dev/null +++ b/popup.min.js @@ -0,0 +1,2 @@ +var popup_window={};function main(){update_config(),start_browse()}function display_error(o,t){return t?(alert(o),!1):confirm(o)}function update_config(){popup_window.parameters="scrollbars=no, status=no, location=no, toolbar=no, menubar=no"}function request_URL(){for(;;){var o,t=String(prompt("Input a URL of another website or of a page within.")).trim();if(o=t,RegExp("^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*(\\?[;&a-z\\d%_.~+=-]*)?(\\#[-a-z\\d_]*)?$","i").test(o))return popup_window.URL=t,!0;if(!t)return!1}}function display_URL(o){for(;;){var t={};if(t.status=window.open(o,o,popup_window.parameters),t.status)return!0;if(!display_error(`The pop-up has been blocked! +To continue, try un-blocking it first for this site. `))return!1}}function start_browse(){(user_browse_confirm=request_URL())&&display_URL(popup_window.URL)}main(); \ No newline at end of file