mirror of
https://github.com/NohamR/Pocket-Bird.git
synced 2026-05-25 19:59:38 +00:00
Extract url comparison
This commit is contained in:
42
birb.js
42
birb.js
@@ -857,6 +857,46 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StickyNote} stickyNote
|
||||||
|
* @returns {boolean} Whether the given sticky note is applicable to the current site/page
|
||||||
|
*/
|
||||||
|
function isStickyNoteApplicable(stickyNote) {
|
||||||
|
const stickyNoteUrl = stickyNote.site;
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const stickyNoteWebsite = stickyNoteUrl.split("?")[0];
|
||||||
|
const currentWebsite = currentUrl.split("?")[0];
|
||||||
|
|
||||||
|
debug("Comparing " + stickyNoteUrl + " with " + currentUrl);
|
||||||
|
|
||||||
|
if (stickyNoteWebsite !== currentWebsite) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|
||||||
|
if (window.location.hostname === "www.youtube.com") {
|
||||||
|
if (currentParams.v !== undefined && currentParams.v !== stickyNoteParams.v) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -911,7 +951,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
// Render all sticky notes
|
// Render all sticky notes
|
||||||
for (let stickyNote of stickyNotes) {
|
for (let stickyNote of stickyNotes) {
|
||||||
if (stickyNote.site.split("?")[0] === window.location.href.split("?")[0]) {
|
if (isStickyNoteApplicable(stickyNote)) {
|
||||||
renderStickyNote(stickyNote);
|
renderStickyNote(stickyNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2
build.js
2
build.js
@@ -24,7 +24,7 @@ const userScriptHeader =
|
|||||||
`// ==UserScript==
|
`// ==UserScript==
|
||||||
// @name Browser Bird
|
// @name Browser Bird
|
||||||
// @namespace https://idreesinc.com
|
// @namespace https://idreesinc.com
|
||||||
// @version 2025-08-16-3
|
// @version 2025-08-16-4
|
||||||
// @description birb
|
// @description birb
|
||||||
// @author Idrees
|
// @author Idrees
|
||||||
// @downloadURL https://github.com/IdreesInc/Browser-Bird/raw/refs/heads/main/dist/birb.user.js
|
// @downloadURL https://github.com/IdreesInc/Browser-Bird/raw/refs/heads/main/dist/birb.user.js
|
||||||
|
|||||||
42
dist/birb.js
vendored
42
dist/birb.js
vendored
@@ -1175,6 +1175,46 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StickyNote} stickyNote
|
||||||
|
* @returns {boolean} Whether the given sticky note is applicable to the current site/page
|
||||||
|
*/
|
||||||
|
function isStickyNoteApplicable(stickyNote) {
|
||||||
|
const stickyNoteUrl = stickyNote.site;
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const stickyNoteWebsite = stickyNoteUrl.split("?")[0];
|
||||||
|
const currentWebsite = currentUrl.split("?")[0];
|
||||||
|
|
||||||
|
debug("Comparing " + stickyNoteUrl + " with " + currentUrl);
|
||||||
|
|
||||||
|
if (stickyNoteWebsite !== currentWebsite) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|
||||||
|
if (window.location.hostname === "www.youtube.com") {
|
||||||
|
if (currentParams.v !== undefined && currentParams.v !== stickyNoteParams.v) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -1229,7 +1269,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
// Render all sticky notes
|
// Render all sticky notes
|
||||||
for (let stickyNote of stickyNotes) {
|
for (let stickyNote of stickyNotes) {
|
||||||
if (stickyNote.site.split("?")[0] === window.location.href.split("?")[0]) {
|
if (isStickyNoteApplicable(stickyNote)) {
|
||||||
renderStickyNote(stickyNote);
|
renderStickyNote(stickyNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
44
dist/birb.user.js
vendored
44
dist/birb.user.js
vendored
@@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Browser Bird
|
// @name Browser Bird
|
||||||
// @namespace https://idreesinc.com
|
// @namespace https://idreesinc.com
|
||||||
// @version 2025-08-16-3
|
// @version 2025-08-16-4
|
||||||
// @description birb
|
// @description birb
|
||||||
// @author Idrees
|
// @author Idrees
|
||||||
// @downloadURL https://github.com/IdreesInc/Browser-Bird/raw/refs/heads/main/dist/birb.user.js
|
// @downloadURL https://github.com/IdreesInc/Browser-Bird/raw/refs/heads/main/dist/birb.user.js
|
||||||
@@ -1189,6 +1189,46 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
save();
|
save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {StickyNote} stickyNote
|
||||||
|
* @returns {boolean} Whether the given sticky note is applicable to the current site/page
|
||||||
|
*/
|
||||||
|
function isStickyNoteApplicable(stickyNote) {
|
||||||
|
const stickyNoteUrl = stickyNote.site;
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const stickyNoteWebsite = stickyNoteUrl.split("?")[0];
|
||||||
|
const currentWebsite = currentUrl.split("?")[0];
|
||||||
|
|
||||||
|
debug("Comparing " + stickyNoteUrl + " with " + currentUrl);
|
||||||
|
|
||||||
|
if (stickyNoteWebsite !== currentWebsite) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const stickyNoteParams = stickyNoteUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
/** @type {Record<string, string>} */
|
||||||
|
const currentParams = currentUrl.split("?")[1]?.split("&").reduce((params, param) => {
|
||||||
|
const [key, value] = param.split("=");
|
||||||
|
params[key] = value;
|
||||||
|
return params;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
debug("Comparing params: ", stickyNoteParams, currentParams);
|
||||||
|
|
||||||
|
if (window.location.hostname === "www.youtube.com") {
|
||||||
|
if (currentParams.v !== undefined && currentParams.v !== stickyNoteParams.v) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
if (window !== window.top) {
|
if (window !== window.top) {
|
||||||
// Skip installation if within an iframe
|
// Skip installation if within an iframe
|
||||||
@@ -1243,7 +1283,7 @@ Promise.all([loadSpriteSheetPixels(SPRITE_SHEET), loadSpriteSheetPixels(DECORATI
|
|||||||
|
|
||||||
// Render all sticky notes
|
// Render all sticky notes
|
||||||
for (let stickyNote of stickyNotes) {
|
for (let stickyNote of stickyNotes) {
|
||||||
if (stickyNote.site.split("?")[0] === window.location.href.split("?")[0]) {
|
if (isStickyNoteApplicable(stickyNote)) {
|
||||||
renderStickyNote(stickyNote);
|
renderStickyNote(stickyNote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user