Skip to content

Commit

Permalink
refactored to easily add new features, add new feature, adding custom…
Browse files Browse the repository at this point in the history
… crosshair, only not for sniper rifle, since in game it can be done via game settings.
  • Loading branch information
MoriorInvictus committed Sep 28, 2022
1 parent f2b3d25 commit 6b8f9c6
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 32 deletions.
7 changes: 7 additions & 0 deletions assets/css/features/change_bg/main.css
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@


#app > div{

z-index: 2;

}


36 changes: 36 additions & 0 deletions assets/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,48 @@ input[type=number] {



.file-input-label {

margin-top: 20px;
display: block;
cursor: pointer;

}


.file-input-label input{

width: 0;
height: 0;
overflow: hidden;
visibility: hidden;
position: absolute;
left: -100%;


}


.file-input-label span{

text-align: center;
color: #041C40;
font-size: 16px;
font-weight: 700;
border: 2px solid #041C40;
border-radius: 0.6em;
padding: 15px;
transition: .3s;

}



.file-input-label:hover span{

border-color: limegreen;

}



2 changes: 2 additions & 0 deletions assets/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ const convertImageToBase64Image = async (url) => {





socket_tasks = {
'convertImageToBase64': convertImageToBase64Image,
};
1 change: 1 addition & 0 deletions assets/js/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ socket_tasks = {
'handleBgChanging': handleBgChange,
'handleResetBg': handleResetBg,
'handleBorderRadiusUpdate': handleBorderRadiusUpdate,
'handleCrosshairChanging': handleCrosshairChanging,
};


Expand Down
118 changes: 118 additions & 0 deletions assets/js/features/crosshair/injected__ch-change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@


function handleCrosshairChanging(base64Img){

if(!base64Img){
base64Img = '';
}



updateStorage({
'voxiomDefaultCrosshair': base64Img
})
updateCrossHair(base64Img);


}






function updateCrossHair(base64Img) {

existedCrossHairs = getElements('.custom-crosshair');
if(existedCrossHairs.length > 0){
existedCrossHairs.forEach(crosshair => {
if(crosshair){
try{
crosshair.remove();
} catch(e){

}
}
})
}

if(!base64Img){
return false;
}


newCrossHair = document.createElement("img");
addClass(newCrossHair, 'custom-crosshair');
newCrossHair.src = base64Img;
newCrossHair.onload = _ => {
crossHairStyle = {

"position": 'fixed !important',
"top": '50%',
"left": '50%',
"transform": 'translate(-50%, -50%)',
"z-index": '1',
"opacity": '1',

};

newCrossHair.style.cssText = objectToCssTextStyles(crossHairStyle);

appendToElement('#app', newCrossHair);
}



}




waitForElm('.sc-frCSdB').then((elm) => {
customGameSniperCrossHair = getElement('.sc-frCSdB');

if(customGameSniperCrossHair){

const customCrossHairconfig = {
attributes: true
};
const customCrossHairCallback = function(mutationsList, observer) {
for (let mutation of mutationsList) {
if (mutation.type === 'attributes') {
if(customGameSniperCrossHair.style.opacity == '1'){
getElement('.custom-crosshair').style.opacity = '0';
} else{
getElement('.custom-crosshair').style.opacity = '1';
}

}
}
};

const customCrossHairObserver = new MutationObserver(customCrossHairCallback);

customCrossHairObserver.observe(customGameSniperCrossHair, customCrossHairconfig);

}

});



function launchUpdatingCrossHair() {
bgImageFromCache = getFromStorage('voxiomDefaultCrosshair');
if(bgImageFromCache === undefined) return updateCrossHair(false);
updateCrossHair(bgImageFromCache);
}

launchUpdatingCrossHair(false);










36 changes: 36 additions & 0 deletions assets/js/features/crosshair/popup__ch-change.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

base64String = '';
async function crosshairUpdateHandler(fileInput){
if(!fileInput){
try{
return await sendMessageToActiveTab({ task: 'handleCrosshairChanging', args: [false] }, _ => {console.log('must to update')})
} catch(e){

}
}
file = fileInput['files'][0];

const reader = new FileReader();

reader.onload = async function () {
base64String = reader.result;
try{
return await sendMessageToActiveTab({ task: 'handleCrosshairChanging', args: [reader.result] }, _ => {console.log('must to update')})
} catch(e){

}

};

reader.readAsDataURL(file);
return base64String;
}









6 changes: 0 additions & 6 deletions assets/js/page.js

This file was deleted.

Loading

0 comments on commit 6b8f9c6

Please sign in to comment.