Skip to content

Commit

Permalink
Background supports every image types
Browse files Browse the repository at this point in the history
  • Loading branch information
victrme committed Apr 2, 2020
1 parent 1358866 commit 87929ff
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 21 deletions.
34 changes: 27 additions & 7 deletions src/scripts/local.js
Original file line number Diff line number Diff line change
Expand Up @@ -1191,12 +1191,13 @@ function imgBackground(val) {
//fait ?
function initBackground(initStorage) {

function loadCustom(d) {
function loadCustom({custom, customIndex}) {

const cleanData = d.custom.replace("data:image/jpeg;base64,", "")

imgBackground(b64toBlobUrl(cleanData));
changeImgIndex(d.customIndex);
imgBackground(b64toBlobUrl(
custom.slice(custom.indexOf(",") + 1, custom.length)
));

changeImgIndex(customIndex);
}

let type = initStorage.background_type || "dynamic";
Expand Down Expand Up @@ -1279,7 +1280,22 @@ let fullThumbnails = []
const domimg = id('background')
const domthumbnail = document.getElementsByClassName('thumbnail')

function b64toBlobUrl(a,b="",c=512){const d=atob(a),e=[];for(let f=0;f<d.length;f+=c){const a=d.slice(f,f+c),b=Array(a.length);for(let c=0;c<a.length;c++)b[c]=a.charCodeAt(c);const g=new Uint8Array(b);e.push(g)}const f=new Blob(e,{type:b}),g=URL.createObjectURL(f);return g}
function b64toBlobUrl(a, b = "", c = 512) {
const d = atob(a),
e = [];
for (let f = 0; f < d.length; f += c) {
const a = d.slice(f, f + c),
b = Array(a.length);
for (let c = 0; c < a.length; c++) b[c] = a.charCodeAt(c);
const g = new Uint8Array(b);
e.push(g)
}
const f = new Blob(e, {
type: b
}),
g = URL.createObjectURL(f);
return g
}

function changeImgIndex(i) {domimg.setAttribute("index", i)}

Expand Down Expand Up @@ -1341,7 +1357,7 @@ function compress(e, state) {

//renvoie le base64
const data = ctx.canvas.toDataURL(img);
const cleanData = data.replace("data:image/png;base64,", ""); //used for blob
const cleanData = data.slice(data.indexOf(",") + 1, data.length)


if (state === "thumbnail") {
Expand Down Expand Up @@ -1795,6 +1811,10 @@ function signature() {
//fait
function showPopup(data) {

id("go").setAttribute("href", (navigator.userAgent.includes("Chrome")
? "https://chrome.google.com/webstore/detail/bonjourr-%C2%B7-minimalist-lig/dlnejlppicbjfcfcedcflplfjajinajd/reviews"
: "https://addons.mozilla.org/en-US/firefox/addon/bonjourr-startpage/"))

//s'affiche après 10 tabs
if (data > 10) {

Expand Down
38 changes: 24 additions & 14 deletions src/scripts/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,14 @@ function imgBackground(val) {

function initBackground(storage) {

function loadCustom(d) {
function loadCustom({custom, customIndex}) {

const index = (d.customIndex >= 0 ? d.customIndex : 0),
cleanData = d.custom[index].replace("data:image/jpeg;base64,", "")
const index = (customIndex >= 0 ? customIndex : 0)
const chosen = custom[index]
const cleanData = chosen.slice(chosen.indexOf(",") + 1, chosen.length)

imgBackground(b64toBlobUrl(cleanData));
changeImgIndex(d.customIndex);
changeImgIndex(customIndex);
}

let type = storage.background_type || "dynamic";
Expand Down Expand Up @@ -1267,7 +1268,22 @@ let fullThumbnails = []
const domimg = id('background')
const domthumbnail = document.getElementsByClassName('thumbnail')

function b64toBlobUrl(a,b="",c=512){const d=atob(a),e=[];for(let f=0;f<d.length;f+=c){const a=d.slice(f,f+c),b=Array(a.length);for(let c=0;c<a.length;c++)b[c]=a.charCodeAt(c);const g=new Uint8Array(b);e.push(g)}const f=new Blob(e,{type:b}),g=URL.createObjectURL(f);return g}
function b64toBlobUrl(a, b = "", c = 512) {
const d = atob(a),
e = [];
for (let f = 0; f < d.length; f += c) {
const a = d.slice(f, f + c),
b = Array(a.length);
for (let c = 0; c < a.length; c++) b[c] = a.charCodeAt(c);
const g = new Uint8Array(b);
e.push(g)
}
const f = new Blob(e, {
type: b
}),
g = URL.createObjectURL(f);
return g
}

function changeImgIndex(i) {domimg.setAttribute("index", i)}

Expand All @@ -1291,7 +1307,6 @@ function renderImage(file, is) {
reader.readAsDataURL(file);
}

//3
function compress(e, state) {
//prend l'image complete en arg

Expand All @@ -1312,15 +1327,14 @@ function compress(e, state) {
elem.width = img.width * scaleFactor;
elem.height = height;



//dessine l'image proportionné
ctx.drawImage(img, 0, 0, img.width * scaleFactor, height);

//renvoie le base64
const data = ctx.canvas.toDataURL(img);
const cleanData = data.replace("data:image/png;base64,", ""); //used for blob
const cleanData = data.slice(data.indexOf(",") + 1, data.length) //used for blob

console.log(cleanData)

if (state === "thumbnail") {

Expand All @@ -1339,8 +1353,6 @@ function compress(e, state) {
chrome.storage.local.set({customIndex: fullImage.length - 1});
}



//affiche l'image
imgBackground(b64toBlobUrl(cleanData));
}
Expand All @@ -1349,7 +1361,6 @@ function compress(e, state) {
img.src = e;
}

//4
function addThumbnails(data, index) {

//créer une tag html en plus + remove button
Expand Down Expand Up @@ -1426,7 +1437,6 @@ function addThumbnails(data, index) {
}
}


function unsplash(data, event, startup) {

//on startup nothing is displayed
Expand Down Expand Up @@ -1783,7 +1793,7 @@ function showPopup(data) {

id("go").setAttribute("href", (navigator.userAgent.includes("Chrome")
? "https://chrome.google.com/webstore/detail/bonjourr-%C2%B7-minimalist-lig/dlnejlppicbjfcfcedcflplfjajinajd/reviews"
: "https://addons.mozilla.org/en-US/firefox/addon/bonjourr-startpage/"))
: "https://addons.mozilla.org/en-US/firefox/addon/bonjourr-startpage/"))

//s'affiche après 10 tabs
if (data > 10) {
Expand Down
2 changes: 2 additions & 0 deletions src/styles/events.css
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ body.autodark #settings #cssEditor:focus::placeholder {
}

#settings #fileContainer {
min-width: 120px;
margin-right: 1em;
border: 1px solid transparent;
padding: 1em;
border: 1px dashed #ccc;
Expand Down

0 comments on commit 87929ff

Please sign in to comment.