Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SatoX69 committed Oct 5, 2024
1 parent 6c6b182 commit 634e299
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
# Facebook-Story
A really simple extension for extracting Facebook Story CDN links

## How It Works
1. **Check for Element:** The script checks for a specific `<div>` element on a the `facebook.com/stories` url for extracting the CDN.
2. **Find Video URL:** It scans the entire HTML content of the page to find all `data-video-url` values and get the last one (Which seems to be in higher quality (to me))
3. **Retry:** If the element is not found, it waits for 2 seconds and checks again.

## Usage
1. Add this script to your browser's console or include it in a web page.
2. Open the console to see the logs.
3. Watch for messages about the element and the last video URL.

## Note/Concerns
The script doesn't always seem to be actively running whenever the story is opened. It only seems to run whenever the story page (`facebook.com/stories`) is directly opened or refreshed.
12 changes: 12 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url && tab.url.startsWith("https://www.facebook.com/stories/")) {
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['content.js']
});
}
});

chrome.action.onClicked.addListener((tab) => {
chrome.tabs.create({ url: "https://github.com/SatoX69/Facebook-Story" });
});
32 changes: 32 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function CDN_Elem() {
const element = document.querySelector('div[data-force-autoplay="false"][data-use-device-sound-state="true"]');

if (element) {
var htmlContent = document.documentElement.innerHTML;
var regex = /data-video-url="(.*?)"/g;
var lastVideoUrl;
var match;

while ((match = regex.exec(htmlContent)) !== null) {
lastVideoUrl = match[1];
}

if (lastVideoUrl) {
lastVideoUrl = CDN_link(lastVideoUrl);
if (confirm(`Open Story`)) {
window.open(lastVideoUrl, '_blank');
}
} else {
console.log("No CDN Found");
}
} else {
console.log("CDN not found, retrying...");
setTimeout(CDN_Elem, 2000);
}
}

CDN_Elem();

function CDN_link(str) {
return str.replace(/&amp;/g, "&");
}
Binary file added icons/icon128.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 icons/icon16.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 icons/icon48.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"manifest_version": 3,
"name": "FB Story CDN",
"version": "1.0",
"description": "Extracts the FB Story element for sharing or downloading directly. (Refresh on the story page to activate it)",
"permissions": ["activeTab", "scripting"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["https://www.facebook.com/stories/*"],
"js": ["content.js"]
}
],
"icons": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
},
"action": {
"default_icon": {
"16": "icons/icon16.png",
"48": "icons/icon48.png",
"128": "icons/icon128.png"
}
}
}

0 comments on commit 634e299

Please sign in to comment.