Skip to content

betterSummerHC #243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions submissions/betterSummerHC/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# betterSummerHC

## Overview

**betterSummerHC** is an extension that makes the Summer HackClub experience better with new features!

---

## Features

- **Hide Items** Hide all the items you don't want or have already buyed from the shop page.

## Usage

1. Open summer in a new page in the browser [https://summer.hackclub.com/](https://summer.hackclub.com/).
2. You will instantly see modified pages
Binary file added submissions/betterSummerHC/assets/favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added submissions/betterSummerHC/assets/favicon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added submissions/betterSummerHC/assets/favicon16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added submissions/betterSummerHC/assets/favicon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions submissions/betterSummerHC/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"manifest_version": 3,
"name": "betterSummerHC",
"version": "0.1.0",
"description": "An extension that makes the Summer HackClub experience better with new features!",
"permissions": [
"activeTab",
"storage"
],
"host_permissions": [
"https://summer.hackclub.com/*"
],
"action": {
"default_popup": "popup.html",
"default_icon": "assets/favicon128.png"
},
"content_scripts": [
{
"matches": [
"https://summer.hackclub.com/*"
],
"js": [
"scripts/browser-polyfill.min.js",
"scripts/content.js",
"scripts/shop.js"
]
},
{
"matches": [
"https://summer.hackclub.com/*"
],
"js": [
"scripts/firefoxfix.js"
],
"world": "MAIN"
}
],
"icons": {
"16": "assets/favicon16.png",
"48": "assets/favicon48.png",
"128": "assets/favicon128.png"
},
"browser_specific_settings": {
"gecko": {
"id": "[email protected]"
}
}
}
44 changes: 44 additions & 0 deletions submissions/betterSummerHC/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" href="styles/popup.css">
<script defer src="scripts/browser-polyfill.min.js"></script>
<script src="popup.js" defer></script>
</head>

<body>
<div class="tabs">
<button data-tab="general">General</button>
<button data-tab="shop" data-url="/shop" >Shop</button>
<button data-tab="new" class="active">New Features</button>
</div>

<div class="content" id="general">
<h2>General Settings</h2>

<div class="settings">
<label class="checkbox">
Hide Info buttons
<input type="checkbox" id="hide-info">
</label>
</div>
</div>

<div class="content" id="shop">
<div class="hidden">

<p>Hidden items</p>
<div>

</div>
</div>
</div>

<div class="content active" id="new">
<h2>New Features</h2>
<p>Stay tuned for more updates!</p>
</div>
</body>

</html>
108 changes: 108 additions & 0 deletions submissions/betterSummerHC/popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const tabsBtns = document.querySelectorAll('.tabs button');

function toggleTab(tabName) {
tabsBtns.forEach(btn => btn.classList.remove('active'));
document.querySelectorAll('.content').forEach(tab => tab.classList.remove('active'));

const bt = document.querySelector(`button[data-tab="${tabName}"]`);
if (!bt) {
console.error(`Button for tab '${tabName}' not found.`);
return;
}
bt.classList.add('active');
document.querySelector(`#${bt.dataset.tab}`).classList.add('active');
}

tabsBtns.forEach(bt => {
if (bt.dataset.url != undefined) {
const url = `https://summer.hackclub.com${bt.dataset.url}`;

browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
const currentTab = tabs[0];
if (currentTab.url === url) {
toggleTab(bt.dataset.tab);
}
}).catch(err => console.error('Error querying tabs:', err));
}

bt.addEventListener('click', () => {
if (bt.dataset.url != undefined) {
const url = `https://summer.hackclub.com${bt.dataset.url}`;

browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
const currentTab = tabs[0];
if (!(currentTab.url === url)) {
browser.tabs.update(currentTab.id, { url: url });
}
}).catch(err => console.error('Error querying tabs:', err));
}
toggleTab(bt.dataset.tab);
});
});

(async () => {
const result = await browser.storage.sync.get(["shopHidden"]);
if (!result) {
browser.storage.sync.set({ shopHidden: [] }, () => {
console.warn("No hidden items found. Creating new list.");
});
return;
}

const shopHidden = result.shopHidden || [];

const hideDiv = document.querySelector('.hidden > div');
hideDiv.innerHTML = '';
shopHidden.forEach(item => {
const itemElement = document.createElement('div');
itemElement.textContent = item.split(".")[1].trim();

const unhideButton = document.createElement('button');
unhideButton.textContent = 'Unhide';
unhideButton.addEventListener('click', () => {
browser.storage.sync.get(["shopHidden"]).then(res => {
const updated = res.shopHidden.filter(i => i !== item);
browser.storage.sync.set({ shopHidden: updated }).then(() => {
itemElement.remove();
});

browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
const activeTab = tabs[0];
browser.tabs.sendMessage(activeTab.id, { action: 'unhide', id: item })
.catch(err => console.warn('Content script may not be loaded in this tab:', err));
});
});
});

itemElement.appendChild(unhideButton);
hideDiv.appendChild(itemElement);
});

document.querySelector('.hidden').style.display = shopHidden.length > 0 ? 'block' : 'none';
})().catch(err => console.error('Error loading hidden items:', err));

// General
const infoButton = document.querySelector("input#hide-info");

if (infoButton) {
infoButton.addEventListener("change", async (e) => {
const hideInfoBanner = e.target.checked;
console.info("Setting hideInfoBanner to:", hideInfoBanner);

await browser.storage.sync.set({ hideInfoBanner });
console.info("hideInfoBanner updated in storage.");

browser.tabs.query({ active: true, currentWindow: true }).then(tabs => {
const activeTab = tabs[0];
browser.tabs.sendMessage(activeTab.id, { action: 'hideInfoBanner', force: hideInfoBanner })
.catch(err => console.warn('Content script may not be loaded in this tab:', err));
});
});

(async () => {
const result = await browser.storage.sync.get(["hideInfoBanner"]);
console.log(result)

infoButton.checked = result.hideInfoBanner || false;
})();
}
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions submissions/betterSummerHC/scripts/browser-polyfill.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions submissions/betterSummerHC/scripts/content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Pulsante Info
async function hideInfoBanner(force = false) {
const result = await browser.storage.sync.get(["hideInfoBanner"]);
console.info("Hide Info Banner result:", result);

const infoBanner = document.querySelector('.tutorial-help-btn');

if (!force && !result.hideInfoBanner) {
if (infoBanner) {
infoBanner.style.display = 'block';
}
console.info("Info Banner not hidden as per user preference.");
return;
}

if (infoBanner) {
infoBanner.style.display = 'none';
}
}
hideInfoBanner();

window.addEventListener("custom:navigation", (e) => {
hideInfoBanner();
});
browser.runtime.onMessage.addListener((message) => {
if (message.action === 'hideInfoBanner') {
hideInfoBanner(message.force);
}
});
22 changes: 22 additions & 0 deletions submissions/betterSummerHC/scripts/firefoxfix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(function() {
const origPush = history.pushState;
const origReplace = history.replaceState;

function fireEvent() {
window.dispatchEvent(new CustomEvent("custom:navigation", {
detail: { url: location.href }
}));
}

history.pushState = function(...args) {
origPush.apply(this, args);
fireEvent();
};

history.replaceState = function(...args) {
origReplace.apply(this, args);
fireEvent();
};

window.addEventListener("popstate", fireEvent);
})();
Loading