Skip to content

Instantly share code, notes, and snippets.

@dvygolov
Last active September 4, 2024 10:24
Show Gist options
  • Save dvygolov/f7fe4b3991d426e2dc12441be9f73a54 to your computer and use it in GitHub Desktop.
Save dvygolov/f7fe4b3991d426e2dc12441be9f73a54 to your computer and use it in GitHub Desktop.
FB Asian cookies converter as a browser bookmarklet
//Script as a bookmarklet
javascript:(async () => {var div = document.createElement('div'); div.style.position = 'fixed'; div.style.top = '50%'; div.style.left = '50%'; div.style.transform = 'translate(-50%, -50%)'; div.style.width = '400px'; div.style.padding = '20px'; div.style.backgroundColor = 'yellow'; div.style.border = '2px solid black'; div.style.borderRadius = '10px'; div.style.zIndex = '10000'; div.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)'; var titleContainer = document.createElement('div'); titleContainer.style.display = 'flex'; titleContainer.style.alignItems = 'center'; titleContainer.style.justifyContent = 'center'; titleContainer.style.marginBottom = '10px'; var blurToggle = document.createElement('button'); blurToggle.innerText = '👁️'; blurToggle.style.backgroundColor = 'transparent'; blurToggle.style.border = 'none'; blurToggle.style.cursor = 'pointer'; blurToggle.style.fontSize = '20px'; blurToggle.style.marginRight = '10px'; blurToggle.style.opacity = '1'; titleContainer.appendChild(blurToggle); var title = document.createElement('div'); title.innerText = 'FB Asian Cookies Converter'; title.style.fontSize = '18px'; title.style.fontWeight = 'bold'; title.style.color = 'brown'; title.style.textAlign = 'center'; titleContainer.appendChild(title); div.appendChild(titleContainer); var closeButton = document.createElement('button'); closeButton.innerText = 'X'; closeButton.style.position = 'absolute'; closeButton.style.top = '10px'; closeButton.style.right = '10px'; closeButton.style.backgroundColor = 'red'; closeButton.style.color = 'white'; closeButton.style.border = 'none'; closeButton.style.borderRadius = '50%'; closeButton.style.width = '25px'; closeButton.style.height = '25px'; closeButton.style.cursor = 'pointer'; div.appendChild(closeButton); var inputContainer = document.createElement('div'); inputContainer.style.position = 'relative'; var inputArea = document.createElement('textarea'); inputArea.style.width = '100%'; inputArea.style.height = '100px'; inputArea.placeholder = 'Enter cookies here...'; inputContainer.appendChild(inputArea); div.appendChild(inputContainer); var convertButton = document.createElement('button'); convertButton.innerText = 'Convert'; convertButton.style.display = 'block'; convertButton.style.margin = '10px auto'; div.appendChild(convertButton); var outputArea = document.createElement('textarea'); outputArea.style.width = '100%'; outputArea.style.height = '100px'; outputArea.readOnly = true; div.appendChild(outputArea); var copyButton = document.createElement('button'); copyButton.innerText = 'Copy to Clipboard'; copyButton.style.display = 'block'; copyButton.style.margin = '10px auto'; div.appendChild(copyButton); var footer = document.createElement('div'); footer.style.textAlign = 'center'; footer.style.marginTop = '10px'; var link = document.createElement('a'); link.href = 'https://t.me/yellow_web'; link.innerText = 'by Yellow Web'; link.style.fontSize = '10px'; link.style.color = 'blue'; footer.appendChild(link); div.appendChild(footer); document.body.appendChild(div); blurToggle.addEventListener('click', function() { if (inputArea.style.filter === 'blur(5px)') { inputArea.style.filter = 'none'; blurToggle.style.opacity = '1'; } else { inputArea.style.filter = 'blur(5px)'; blurToggle.style.opacity = '0.5'; } }); convertButton.addEventListener('click', function() { var baseCookie = { "domain": ".facebook.com", "expirationDate": Math.floor(Date.now() / 1000) + 6 * 30 * 24 * 60 * 60, "path": "/", "sameSite": "None", "secure": true, "session": true }; var httpOnlyCookies = ["sb", "datr", "xs"]; var cookies = inputArea.value.split(';'); var jsonCookies = []; var hasCUser = false; var hasXS = false; cookies.forEach(function(cookie) { if (cookie.trim() === '') return; var [name, value] = cookie.trim().split('=', 2); if (name === 'noscript') return; if (name === 'c_user') hasCUser = true; if (name === 'xs') hasXS = true; var cookieDetails = { ...baseCookie, name, value }; cookieDetails.httpOnly = httpOnlyCookies.includes(name); jsonCookies.push(cookieDetails); }); if (!hasCUser || !hasXS) { alert('No c_user or xs cookie found!'); } outputArea.value = JSON.stringify(jsonCookies, null, 2); }); copyButton.addEventListener('click', function() { outputArea.select(); document.execCommand('copy'); alert('JSON copied to clipboard!'); }); closeButton.addEventListener('click', function() { document.body.removeChild(div); });})();
//Original script
// Create a div for the interface
var div = document.createElement('div');
div.style.position = 'fixed';
div.style.top = '50%';
div.style.left = '50%';
div.style.transform = 'translate(-50%, -50%)';
div.style.width = '400px';
div.style.padding = '20px';
div.style.backgroundColor = 'yellow';
div.style.border = '2px solid black';
div.style.borderRadius = '10px';
div.style.zIndex = '10000';
div.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.5)';
// Create a container for the title and blur toggle
var titleContainer = document.createElement('div');
titleContainer.style.display = 'flex';
titleContainer.style.alignItems = 'center';
titleContainer.style.justifyContent = 'center';
titleContainer.style.marginBottom = '10px';
// Create a toggle button for blur
var blurToggle = document.createElement('button');
blurToggle.innerText = '👁️';
blurToggle.style.backgroundColor = 'transparent';
blurToggle.style.border = 'none';
blurToggle.style.cursor = 'pointer';
blurToggle.style.fontSize = '20px';
blurToggle.style.marginRight = '10px';
blurToggle.style.opacity = '1';
titleContainer.appendChild(blurToggle);
// Create a title
var title = document.createElement('div');
title.innerText = 'FB Asian Cookies Converter';
title.style.fontSize = '18px';
title.style.fontWeight = 'bold';
title.style.color = 'brown';
title.style.textAlign = 'center';
titleContainer.appendChild(title);
div.appendChild(titleContainer);
// Create a close button
var closeButton = document.createElement('button');
closeButton.innerText = 'X';
closeButton.style.position = 'absolute';
closeButton.style.top = '10px';
closeButton.style.right = '10px';
closeButton.style.backgroundColor = 'red';
closeButton.style.color = 'white';
closeButton.style.border = 'none';
closeButton.style.borderRadius = '50%';
closeButton.style.width = '25px';
closeButton.style.height = '25px';
closeButton.style.cursor = 'pointer';
div.appendChild(closeButton);
// Create a container for the input area
var inputContainer = document.createElement('div');
inputContainer.style.position = 'relative';
// Create a textarea for input cookies
var inputArea = document.createElement('textarea');
inputArea.style.width = '100%';
inputArea.style.height = '100px';
inputArea.placeholder = 'Enter cookies here...';
inputContainer.appendChild(inputArea);
div.appendChild(inputContainer);
// Create a button for conversion
var convertButton = document.createElement('button');
convertButton.innerText = 'Convert';
convertButton.style.display = 'block';
convertButton.style.margin = '10px auto';
div.appendChild(convertButton);
// Create a textarea for output JSON
var outputArea = document.createElement('textarea');
outputArea.style.width = '100%';
outputArea.style.height = '100px';
outputArea.readOnly = true;
div.appendChild(outputArea);
// Create a button for copying JSON to clipboard
var copyButton = document.createElement('button');
copyButton.innerText = 'Copy to Clipboard';
copyButton.style.display = 'block';
copyButton.style.margin = '10px auto';
div.appendChild(copyButton);
// Create a footer with a link
var footer = document.createElement('div');
footer.style.textAlign = 'center';
footer.style.marginTop = '10px';
var link = document.createElement('a');
link.href = 'https://t.me/yellow_web';
link.innerText = 'by Yellow Web';
link.style.fontSize = '10px';
link.style.color = 'blue';
footer.appendChild(link);
div.appendChild(footer);
// Append the div to the body
document.body.appendChild(div);
// Add event listener for the blur toggle button
blurToggle.addEventListener('click', function() {
if (inputArea.style.filter === 'blur(5px)') {
inputArea.style.filter = 'none';
blurToggle.style.opacity = '1';
} else {
inputArea.style.filter = 'blur(5px)';
blurToggle.style.opacity = '0.5';
}
});
// Add event listener for the convert button
convertButton.addEventListener('click', function() {
var baseCookie = {
"domain": ".facebook.com",
"expirationDate": Math.floor(Date.now() / 1000) + 6 * 30 * 24 * 60 * 60,
"path": "/",
"sameSite": "None",
"secure": true,
"session": true
};
var httpOnlyCookies = ["sb", "datr", "xs"];
var cookies = inputArea.value.split(';');
var jsonCookies = [];
var hasCUser = false;
var hasXS = false;
cookies.forEach(function(cookie) {
if (cookie.trim() === '') return;
var [name, value] = cookie.trim().split('=', 2);
if (name === 'noscript') return;
if (name === 'c_user') hasCUser = true;
if (name === 'xs') hasXS = true;
var cookieDetails = { ...baseCookie, name, value };
cookieDetails.httpOnly = httpOnlyCookies.includes(name);
jsonCookies.push(cookieDetails);
});
if (!hasCUser || !hasXS) {
alert('No c_user or xs cookie found!');
}
outputArea.value = JSON.stringify(jsonCookies, null, 2);
});
// Add event listener for the copy button
copyButton.addEventListener('click', function() {
outputArea.select();
document.execCommand('copy');
alert('JSON copied to clipboard!');
});
// Add event listener for the close button
closeButton.addEventListener('click', function() {
document.body.removeChild(div);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment