Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
f avif
  • Loading branch information
uncrypt3d committed Aug 28, 2024
1 parent ef03087 commit c77d140
Show file tree
Hide file tree
Showing 5 changed files with 322 additions and 0 deletions.
49 changes: 49 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// background.js

function log(message, type = 'info') {
const timestamp = new Date().toISOString();
switch (type) {
case 'info':
console.log(`%c[INFO - ${timestamp}] ${message}`, 'color: blue');
break;
case 'warn':
console.warn(`%c[WARN - ${timestamp}] ${message}`, 'color: orange');
break;
case 'error':
console.error(`%c[ERROR - ${timestamp}] ${message}`, 'color: red');
break;
default:
console.log(`[LOG - ${timestamp}] ${message}`);
}
}

chrome.runtime.onInstalled.addListener(() => {
log('Media Converter Extension installed');
});

chrome.runtime.onStartup.addListener(() => {
log('Media Converter Extension started');
});

chrome.runtime.onSuspend.addListener(() => {
log('Media Converter Extension suspended');
});

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "fetchImage") {
fetch(request.url)
.then(response => response.blob())
.then(blob => {
const reader = new FileReader();
reader.onloadend = () => {
sendResponse({ dataUrl: reader.result });
};
reader.readAsDataURL(blob);
})
.catch(error => {
console.error('Fetch error:', error);
sendResponse({ error: error.message });
});
return true;
}
});
138 changes: 138 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
const proxies = [
"https://corsproxy.io/?url=",
"https://cors-anywhere.herokuapp.com/",
"https://api.allorigins.win/get?url=",
"https://thingproxy.freeboard.io/fetch/"
];

let currentProxyIndex = 0;
let observer;

function startObserving() {
console.log('Starting to observe media changes');
observer = new MutationObserver(mutations => {
mutations.forEach(mutation => {
mutation.addedNodes.forEach(node => {
if (node.tagName === 'IMG') {
handleImage(node);
}
});
});
});

observer.observe(document.body, { childList: true, subtree: true });
console.log('Observer initialized and listening for DOM changes');
}

function stopObserving() {
if (observer) {
observer.disconnect();
console.log('Observer stopped');
}
}

function handleImage(img) {
console.log(`New media element detected: IMG`);
console.log(`Processing media element: IMG`);

if (!img.src.endsWith('.avif')) {
console.log(`Image is not an AVIF format: ${img.src}`);
return;
}

img.onload = () => {
console.log(`Image loaded: ${img.src}`);
clickAndConvert(img.src);
};

img.onerror = () => {
console.error(`Image load failed: ${img.src}`);
};

if (img.complete) {
img.onload();
} else {
img.src = img.src;
}
}

function clickAndConvert(imageUrl) {
console.log(`Clicking image to trigger full resolution: ${imageUrl}`);
tryFetching(imageUrl);
}

function tryFetching(url) {
if (currentProxyIndex >= proxies.length) {
console.error('All proxies failed');
return;
}

const proxy = proxies[currentProxyIndex];
const proxiedUrl = proxy + encodeURIComponent(url);

fetch(proxiedUrl)
.then(response => {
if (!response.ok) {
throw new Error(`Failed to fetch: ${response.statusText}`);
}
return response.blob();
})
.then(blob => {
const img = new Image();
img.onload = () => {
console.log('Image loaded for conversion');
convertAvifToJpeg(img);
};
img.onerror = () => {
console.error('Image load failed. Trying next proxy...');
currentProxyIndex++;
tryFetching(url);
};
img.src = URL.createObjectURL(blob);
})
.catch(error => {
console.error('Fetching failed:', error);
currentProxyIndex++;
tryFetching(url);
});
}

function convertAvifToJpeg(img) {
console.log('Converting AVIF image to JPEG...');
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');

canvas.width = img.naturalWidth;
canvas.height = img.naturalHeight;

try {
ctx.drawImage(img, 0, 0);
const jpegUrl = canvas.toDataURL('image/jpeg');
console.log('Downloaded JPEG image:', jpegUrl);

const link = document.createElement('a');
link.href = jpegUrl;
link.download = `${generateRandomFilename()}.jpg`;
link.click();
} catch (error) {
console.error('Failed to convert image:', error);
}
}

function generateRandomFilename(length = 10) {
const characters = 'abcdefghijklmnopqrstuvwxyz0123456789';
let result = '';
const charactersLength = characters.length;
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
}
return result;
}

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'startObserving') {
startObserving();
} else if (message.action === 'stopObserving') {
stopObserving();
}
});
19 changes: 19 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"manifest_version": 3,
"name": "Ylis.jpg",
"version": "0.1.0",
"permissions": ["activeTab", "scripting", "storage"],
"background": {
"service_worker": "background.js"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"action": {
"default_popup": "popup.html"
}
}

99 changes: 99 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<!DOCTYPE html>
<html>
<head>
<title>Ylis2.jpg</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-size: cover;
background-position: center;
color: #ffffff;
text-align: center;
overflow: hidden;
}

.container {
width: 250px;
background: rgba(255, 255, 255, 0.9);
border-radius: 10px;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.2);
padding: 20px;
}

h1 {
font-size: 24px;
margin: 0;
color: #333;
}

p {
font-size: 14px;
color: #666;
margin: 10px 0;
}

button {
background-color: #007bff;
color: white;
border: none;
padding: 12px 18px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease, transform 0.2s ease, opacity 0.3s ease;
width: 100%;
margin-top: 20px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
opacity: 0.9;
}

button:hover {
background-color: #252c26;
opacity: 1;
}

button:active {
background-color: #bfd6e6;
transform: scale(0.98);
opacity: 0.8;
}

.creator-button {
background-color: #28a745;
margin-top: 10px;
}

.creator-button:hover {
background-color: #218838;
opacity: 1;
}

.creator-button:active {
background-color: #1e7e34;
opacity: 0.8;
}
</style>
</style>
</head>
<body>
<div class="container">
<h1>Ylis2.jpg</h1>
<h2>makeylilautagreatagain</h2>
<p>AVIF-huutikset.jpg</p>
<button id="convert">AKTIVOI</button>
<button class="creator-button" id="creator">GITHUB</button>
</div>
<script src="popup.js"></script>
<script>
document.getElementById('creator').addEventListener('click', () => {
window.open('https://github.com/uncrypt3d/Ylis2.jpg', '_blank');
});
</script>
</body>
</html>
17 changes: 17 additions & 0 deletions popup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// popup.js
document.addEventListener('DOMContentLoaded', () => {
const backgrounds = [
'https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fgetwallpapers.com%2Fwallpaper%2Ffull%2Fa%2F0%2F7%2F656116.jpg&f=1&nofb=1&ipt=6ef5e82ab7086d7cfa01b0e9b0a48716608e24d8e008bb1b333d112468aab63e&ipo=images',
'https://images.unsplash.com/photo-1648851633100-cd8ae486646e?q=80&w=1664&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'
];
let currentBackgroundIndex = 0;
function changeBackground() {
document.body.style.backgroundImage = `url(${backgrounds[currentBackgroundIndex]})`;
currentBackgroundIndex = (currentBackgroundIndex + 1) % backgrounds.length;
}
changeBackground();
document.body.addEventListener('mousemove', changeBackground);
document.getElementById('convert').addEventListener('click', () => {
console.log('Convert button clicked');
});
});

0 comments on commit c77d140

Please sign in to comment.