Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

me first a pull request #7

Open
wants to merge 18 commits into
base: spokik-dev-events
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const script = document.createElement('script');// create new element script as module
script.setAttribute("type", "module");
script.setAttribute("src", chrome.extension.getURL('kad.js'));
const testModule = document.createElement(`script`)
testModule.setAttribute("type", "module")
testModule.setAttribute("src", chrome.extension.getURL('./modules/alert.js'))

const head = document.head || document.getElementsByTagName("head")[0] || document.documentElement;
head.insertBefore(script, head.lastChild);// add module in head
head.insertBefore(testModule, head.lastChild);
15 changes: 12 additions & 3 deletions kad.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@

"use strict";
"use strict";

import { injectFunction } from './my-script.js';
import { windowForUserScript } from './modules/alert.js';
if (document.location.href === `https://kad.arbitr.ru/`) { windowForUserScript() }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strings that contain url are better to be stored into const

injectFunction();



if (document.location.href != `https://kad.arbitr.ru/`) {
let usersSettings = JSON.parse(localStorage.getItem(`usersSettings`))
Copy link

@CristinaVolk CristinaVolk Sep 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to keep one pattern of quotes, single or double or backward. Usually, if you have just a string use the single quotes ''

if (usersSettings == undefined) {
usersSettings = {
Expand Down Expand Up @@ -442,7 +451,7 @@
});
observer.observe(elem, {
attributes: true,
childList: true
childList: true
})
})
promise.catch((err) => { console.error(`Error: `, err) })
Expand Down Expand Up @@ -520,5 +529,5 @@
return stringReturn
}


}

34 changes: 23 additions & 11 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,30 @@
"version": "2.0.0",
"description": "kad4scan - extensions for work in kad as scanner",
"permissions": [
"https://*.tribalwars2.com/game.php*"
],
"https://*.tribalwars2.com/game.php*"
],
"icons": {
"128": "overflow.png"
},
"browser_action": {
"default_icon": "overflow.png"
},
"content_scripts": [{
"js": ["kad.js"],
"matches": ["https://*.kad.arbitr.ru/Card/*"],
"run_at": "document_end"
}],
"browser_action": {
"default_icon": "overflow.png"
},
"content_scripts": [
{
"js": [
"content.js"
],
"matches": [
"https://*.kad.arbitr.ru/Card/*",
"https://*.kad.arbitr.ru/*"
],
"run_at": "document_end"
}
],
"web_accessible_resources": [
"kad.js",
"my-script.js",
"modules/alert.js"
],
"manifest_version": 2
}
}
64 changes: 64 additions & 0 deletions modules/alert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';


//Функция создает поля для воода года и номера дела
function windowForUserScript() {
let div = document.createElement('div');
div.id = "UserScriptIndex";
div.innerHTML = `А40 -
<input value="" type ="text" class="b-selected-tags" placeholder = "номер дела" id = "NumberWithoutA40" >
<fieldset>
<label>
<input type="button" name="inputYear" value="20" id="year20" checked="checked"> </label>
<label><input type="button" name="inputYear" value="19" id="year19">
</label><label><input type="button" name="inputYear" value="18" id="year18">
</label></fieldset>`;
document.getElementById('b-form-submit').before(div);
// document.getElementById('main-column1').before(div);
let getNumberInput = document.getElementById(NumberWithoutA40);

getNumberInput.oninput = zamena();
function zamena() {
document.getElementById('dich').innerHTML = getNumberInput.value;

let a40 = document.getElementById(NumberWithoutA40).value;
let year20 = document.getElementById(year20).checked;
let year19 = document.getElementById(year19).checked;
let year18 = document.getElementById(year18).checked;
let year = 20;

if (year20 == true) { year = 20; }
else if (year19 == true) { year = 19; }
else if (year18 == true) { year = 18; }
else { alert(`ЕРОР! Чет какая - то шляпа введина в место года`) }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use ternary operators here


let fullNumber = "А40-" + a40 + "-" + year;
document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value = fullNumber;
}

let tooOldYear = document.getElementById(NumberWithoutA40).value;
//Устанавливаем по умолчанию А40-88888-20
document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value = А40 - 88888 - 20;
//пересобирает строку, заменя 2 последний цифры
function setYear(year) {
let newNumber = document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value
let inString = document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value["length"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't like the name XD

var getNewNumber = ``
let i = 0
while (inString - 2 > i) {
getNewNumber = getNewNumber + newNumber[i]
i++
}
getNewNumber = getNewNumber + year
return getNewNumber
}


//Красим фон и меняем год

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you use comments, it means you use bad names ;)

document.getElementById("year20").onclick = function orange() { document.getElementById('main-column1').style.background = "#ffcf65"; document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value = setYear(20); };
document.getElementById("year19").onclick = function orange() { document.getElementById('main-column1').style.background = "#7cf99d"; document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value = setYear(19); };
document.getElementById("year18").onclick = function orange() { document.getElementById('main-column1').style.background = "#86cdff"; document.querySelector(`#sug - cases.tag input[type = "text"]: valid`).value = setYear(18); };
document.getElementById("pager1").onclick = function orange() { document.getElementById('main-column1').style.background = "#e9f0fa";; };//Красив в сток по праву тех
};

export { windowForUserScript };
5 changes: 5 additions & 0 deletions my-script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const injectFunction = () => window.alert('hello, world');

export { injectFunction };