commit 19af25b19e0e1cd90eca541491123a52a9dd0be1 Author: ryana. Date: Sun Aug 11 15:03:22 2024 +0800 iinitial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d766a89 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 ryanamay + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6dda2cc --- /dev/null +++ b/README.md @@ -0,0 +1,101 @@ +
+ +

Chrome Extension v3 Starter

+

A minimal template of a Chrome v3 addon

+
+ +This repository contains a minimal Chrome/Chromium extension that uses the newest version of the manifest (v3). + +You can use it as a basis to develop an extension. +It can also give you more insights about how to turn a v2 extension to v3. + +In other words, this is a **working, installable v3 extension** example meant for you to **jumpstart** the development of your own extension. + + +## Installation +- **Fork** this repo, then **clone your forked repo locally**. If you don't have a github account, you can simply download a zip of the repo and unzip it on your computer. +- **Open [the extensions page](chrome://extensions)** in your browser: `chrome://extensions`. This link works on any chromium-based browser. +- If you did not do it already, **toggle the "developer mode"**. This is usually a toggle button at the top right of the extensions page. +- Click the button **_load unpacked extension_**. +- In the window that pops up, **select the folder that contains this minimal extension**, then **click _ok_**. +- **Done!** A new extension called _Chrome Addon v3 Starter_ should have appeared in the list. + +## Q&A +> Does this work only on Chrome or on **other web browsers** as well? + +At the moment, this works on every chromium-based web browser that supports v3 extensions. +Therefore, you should be able to install this extension on any of the following browsers (as long as they are up-to-date): +- _Free and open-source browsers_: + - Chromium + - Brave +- _Proprietary browsers_: + - Chrome + - Edge + - Vivaldi + - Opera + +> So it doesn't work on **Firefox** or **Safari**? + +No, Firefox uses a different extension format. That being said, it is usually not too hard to port extensions from Chrome to Firefox. +Read [their porting documentation](https://extensionworkshop.com/documentation/develop/porting-a-google-chrome-extension/) for more information. + +Safari uses yet another extension format and porting is usually harder. +You can find more information [here](https://bartsolutions.github.io/2020/11/20/safari-extension/). + +> Does this work on **Chrome for Android/iOS**? + +Chrome for mobile doesn't currently support extensions. + +> I don't need a **popup tool** for my extension! Can I remove it? + +Yes, simply delete the `popup` folder and remove the `default_popup` property from the manifest. + +> I changed some code in the extension, but my **changes aren't taken into account**! + +For most of the changes you make, you will need to reload your extension for the changes to be applied. +To do that, go to the chrome://extensions page and click the reload button of your extension. +Note that most of the changes you will make to the settings page or the popup don't require reloading the extension. + +> Can I follow a **tutorial about a v2 extension** with this? + +Most of what you will find in those tutorials still holds with v3. + +However, a few things (notably best practices) have changed. +You should read the [official migration page (v2 to v3)](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/) before following such a tutorial. + +> When I make an erroneous change in my service worker, the extension doesn't load! How can I **debug a service worker**? + +Using the debugger if your service worker is not loaded is not possible. + +However, if you want to test some piece of code before putting it in your service worker, you can: +- load your extension with a working version of the service worker. +- click on "service worker" on the page _chrome://extensions_. This will open the console attached to the service worker. +- paste your code in the console and see if any error is logged. + +Note that in this console, you have access to anything your service worker has access to, including its variables, functions and chrome APIs. + +> How do I **uninstall** this extension from my browser? + +- Go to the [extensions page](chrome://extensions): chrome://extensions. + There should be a card with the name of this extension as title. + If you don't see such a card, it means the extension is not installed. +- Simply click the _Delete_ button at the bottom of the card. Click _ok_ if a popup asks you for confirmation. The extension is now uninstalled. + +> I want to **push my changes to my own repo**, how do I do this? + +- If you forked this repo and cloned your own fork locally, git will push to your fork on your account automatically (i.e. use the command `git push` or `git push origin `). + +- If you downloaded a zip or simply cloned this repo locally, do the following: + - Create a github account if you don't already have one and install git on your machine. + - Create a new (empty) repo on your github and copy its url. + - Open a terminal in the folder where the extension is cloned. + - Run the command `git init`, then `git commit -am "Initial commit"` + - Run the command `git remote add origin ` + - Run `git push -u origin master`. The extension code is now on your repo, on brnach _master_. + - If you want, you can make the _master_ branch the default one and delete the _main_ branch in the settings of your repo. + +## External resources +- [Official feature summary for manifest v3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/) +- [Migrating from v2 to v3](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/) + [very useful checklist once you think you are done](https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/) +- [Excellent write-ups of a migration](https://github.com/kentbrew/learning-manifest-v3) +- [Another example of a v3 extension (older code)](https://gist.github.com/dotproto/3a328d6b187621b445499ba503599dc0) diff --git a/audio.mp3 b/audio.mp3 new file mode 100644 index 0000000..8df55c5 Binary files /dev/null and b/audio.mp3 differ diff --git a/background.js b/background.js new file mode 100644 index 0000000..cf39aa8 --- /dev/null +++ b/background.js @@ -0,0 +1,10 @@ +chrome.runtime.onMessage.addListener((message, sender, sendResponse) => { + if (message.action === 'checkFocus') { + chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => { + const focusedTabId = tabs[0].id; + sendResponse({ isFocused: sender.tab.id === focusedTabId }); + }); + // Keep the message channel open until sendResponse is called + return true; + } + }); \ No newline at end of file diff --git a/fredbear.gif b/fredbear.gif new file mode 100644 index 0000000..3519624 Binary files /dev/null and b/fredbear.gif differ diff --git a/main.js b/main.js new file mode 100644 index 0000000..a5a5cb5 --- /dev/null +++ b/main.js @@ -0,0 +1,127 @@ +console.log("FNAF jumpscare extension loaded"); +let jumpscare = false; +let jumpscareQueued = false; +function randomDelay() { + // Delay for up to 5 seconds + return Math.floor(Math.random() * 10000); +} + +function randomCheckDelay() { + // Delay for up to 5 seconds + return Math.floor(Math.random() * 5000); +} + +async function isTabFocused(callback) { + // Send a message to the background script to check if the tab is focused + await chrome.runtime.sendMessage({ action: "checkFocus" }, (response) => { + callback(response.isFocused); + }); +} + +async function overlayJumpscare() { + // Initial check if the tab is focused + // Ensure user interaction + let hasInteracted = false; + + function markInteracted() { + hasInteracted = true; + document.removeEventListener("click", markInteracted); + document.removeEventListener("keydown", markInteracted); + } + + // Add event listeners for user interaction + document.addEventListener("click", markInteracted); + document.addEventListener("keydown", markInteracted); + + while (!jumpscareQueued) { + let delay = randomDelay(); + console.log(`[FNAF] Jumpscare opportunity after ${delay / 1000}s`); + await new Promise((r) => setTimeout(r, delay)); + if (Math.random() < 0.03) { + console.log("[FNAF] Freddy wants to jumpscare!"); + jumpscareQueued = true; + } + else { + console.log("[FNAF] Freddy does not want to jumpscare right now."); + } +} + + while (!jumpscare) { + let delay = randomCheckDelay(); + console.log(`[FNAF] Jumpscare queued. Waiting for next opportunity!`); + await new Promise((r) => setTimeout(r, delay)); + await isTabFocused((tabFocused) => { + if (!tabFocused) { + console.log("[FNAF] Freddy is waiting for user to focus tab/window."); + } else if (!hasInteracted) { + console.log( + "[FNAF] Freddy is waiting for the next user interaction." + ); + } else { + if (!jumpscare) { + console.log("[FNAF] Opportunity found."); + jumpscare = true; + if (Math.random() < 0.5) { + console.log("[FNAF] Freddy backed out and left this tab alone!"); + } else { + console.log("[FNAF] Freddy is preparing to jumpscare!"); + executeJumpscare(); + } + } else { + console.log( + "[FNAF] Freddy is deciding!" + ); + } + } + }); + } +} + +function executeJumpscare() { + const fullscreenOverlay = document.createElement("div"); + fullscreenOverlay.style.position = "fixed"; + fullscreenOverlay.style.top = "0"; + fullscreenOverlay.style.left = "0"; + fullscreenOverlay.style.width = "100vw"; + fullscreenOverlay.style.height = "100vh"; + fullscreenOverlay.style.zIndex = "9999"; // Ensure it's on top + + const jumpscareGif = document.createElement("img"); + jumpscareGif.src = chrome.runtime.getURL("assets/fredbear.gif"); + jumpscareGif.style.width = "100%"; + jumpscareGif.style.height = "100%"; + jumpscareGif.style.objectFit = "cover"; // Ensure image covers area + + const jumpscareAudio = document.createElement("audio"); + jumpscareAudio.src = chrome.runtime.getURL("assets/audio.mp3"); + jumpscareAudio.setAttribute("autoplay", "true"); // Start playing immediately + + const fullscreenStatic = document.createElement("img"); + fullscreenStatic.src = chrome.runtime.getURL("assets/static.gif"); + fullscreenStatic.style.width = "100%"; + fullscreenStatic.style.height = "100%"; + fullscreenStatic.style.objectFit = "cover"; // Ensure image covers area + + // Append gif to overlay + fullscreenOverlay.appendChild(jumpscareGif); + + // Append audio to overlay + fullscreenOverlay.appendChild(jumpscareAudio); + + // Append overlay to document body + document.body.appendChild(fullscreenOverlay); + + // Handle jumpscare audio and gif + jumpscareGif.addEventListener("load", () => { + jumpscareAudio.play(); + // Jumpscare gif is 1.5 seconds long + setTimeout(() => { + // Remove Freddy gif + fullscreenOverlay.removeChild(jumpscareGif); + fullscreenOverlay.appendChild(fullscreenStatic); + }, 1500); // Assuming the gif lasts 1.5 seconds + }); +} + +// Execute the jumpscare function +overlayJumpscare(); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..9c04ce8 --- /dev/null +++ b/manifest.json @@ -0,0 +1,31 @@ +{ + "manifest_version": 3, + "name": "fredy faber", + "version": "1.0", + "description": "at least they didn’t give birth to… freddy fazbear, because, if you give birth to, freddy fivebears, he comes out and he says “or, or, or or, or, or, or or, or or, and then he kills michael afton, or he tries to do it, along with his friends, bunny the bonnie, chica the kitchen, foxy the… fox pirate rawr, and yellow freddy, who’s yellow, and weird, and, but it’s not their fault! it’s all because william afton one day was like “hi i’m gonna murder people, ra!” so he murdered kids, but he was also a yellow bunny? and he was like “hi, i’m a yellow bunny, imma kill you” because he had a daughter? who had, like, remnant? gone from her? so he was like, “if i kill kids, i put them in the suits, so that it’s not, it’s not freddy fivebear fault, its actually purple guy fault” and that’s why you don’t give birth to him.", + "permissions": [ + "scripting", + "activeTab", + "tabs" + ], + "background": { + "service_worker": "background.js" + }, + "content_scripts": [ + { + "matches": [""], + "js": ["main.js"] + } + ], + "web_accessible_resources": [ + { + "resources": [ + "assets/audio.mp3", + "assets/fredbear.gif", + "assets/static.gif", + "assets/checker.mp3" + ], + "matches": [""] + } + ] +} diff --git a/static.gif b/static.gif new file mode 100644 index 0000000..38f8610 Binary files /dev/null and b/static.gif differ