Skip to content

Commit 83d914d

Browse files
committed
Added ChemistrySearchExtension project by Swifterhtmler
1 parent 27ee633 commit 83d914d

File tree

7 files changed

+299
-0
lines changed

7 files changed

+299
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
# Chemistry molecular mass calculator
3+
4+
This is chrome extension that helps users check the molacular mass of inputed element from periodic table.
5+
6+
The extension is activated via:
7+
8+
```bash
9+
Alt + U
10+
```
11+
12+
or
13+
14+
```bash
15+
command + U
16+
```
17+
18+
19+
20+
## Installation
21+
22+
```bash
23+
24+
git clone https://github.com/thinkswell/javascript-mini-projects.git
25+
cd ChemistrySearchExtension/Swifterhtmler/
26+
```
27+
28+
## Demo
29+
30+
![alt text](image.png)
31+
32+
33+
34+
## Authors
35+
36+
- [@Swifterhtmler](https://github.com/Swifterhtmler)
37+
38+
## Notes
39+
40+
41+
!! important, the extension currently only works in finnish, but you can modify and translate as you wish !!
42+
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
const result = document.getElementById('result');
2+
3+
4+
document.addEventListener('DOMContentLoaded', function () {
5+
// Set a small delay to ensure focus is applied after the DOM is fully rendered
6+
setTimeout(function() {
7+
document.getElementById('searchField').focus();
8+
}, 110);
9+
});
10+
11+
12+
if (searchField.value === '') {
13+
result.innerHTML = '';
14+
}
15+
16+
searchField.addEventListener('input', function () {
17+
const inputValue = searchField.value.trim();
18+
19+
20+
if (inputValue === '') {
21+
result.innerHTML = '';
22+
return result;
23+
}
24+
25+
26+
let matchedElement = null;
27+
28+
29+
30+
// Check if the input matches the beginning of any element in the periodic table
31+
for (const element in periodicTable) {
32+
if (element.startsWith(inputValue)) {
33+
matchedElement = element;
34+
break;
35+
}
36+
}
37+
38+
if (matchedElement) {
39+
const molarMass = periodicTable[matchedElement];
40+
result.innerHTML = `${matchedElement} moolimassa on: ${molarMass} g /mol`;
41+
42+
navigator.clipboard.writeText(molarMass.toString() + " \\frac{g}{mol} ").then(function () {
43+
// console.log('Molar mass copied to clipboard:', molarMass);
44+
}).catch(function (error) {
45+
console.error('Clipboard write failed:', error);
46+
});
47+
48+
49+
50+
} else {
51+
result.innerHTML = `Alkuainetta "${inputValue}" ei löytynyt`;
52+
}
53+
54+
});
55+
56+
57+
58+
59+
const periodicTable = {
60+
vety: 1.008,
61+
helium: 4.0026,
62+
lithium: 6.94,
63+
beryllium: 9.0122,
64+
boori: 10.81,
65+
hiili: 12.011,
66+
typpi: 14.007,
67+
happi: 16.00,
68+
fluori: 18.998,
69+
neon: 20.180,
70+
natrium: 22.990,
71+
magnesium: 24.305,
72+
alumiini: 26.982,
73+
pii: 28.085,
74+
fosfori: 30.974,
75+
rikki: 32.06,
76+
kloori: 35.45,
77+
argon: 39.948,
78+
kalium: 39.098,
79+
kalsium: 40.078,
80+
skandium: 44.956,
81+
titaani: 47.867,
82+
vanadiini: 50.942,
83+
kromi: 51.996,
84+
mangaani: 54.938,
85+
rauta: 55.85,
86+
koboltti: 58.933,
87+
nikkeli: 58.693,
88+
kupari: 63.546,
89+
sinkki: 65.38,
90+
gallium: 69.723,
91+
germanium: 72.630,
92+
arseeni: 74.922,
93+
seleeni: 78.971,
94+
bromi: 79.904,
95+
krypton: 83.798,
96+
rubidium: 85.468,
97+
strontium: 87.62,
98+
yttrium: 88.906,
99+
zirkonium: 91.224,
100+
niobi: 92.906,
101+
molybdeeni: 95.95,
102+
teknetium: 98,
103+
ruthenium: 101.07,
104+
rodium: 102.91,
105+
palladium: 106.42,
106+
hopea: 107.87,
107+
kadmium: 112.41,
108+
indium: 114.82,
109+
tina: 118.71,
110+
antimonio: 121.76,
111+
telluuri: 127.60,
112+
jodi: 126.90,
113+
ksenon: 131.29,
114+
seesium: 132.91,
115+
baarium: 137.33,
116+
lantaani: 138.91,
117+
cerium: 140.12,
118+
praseodyymi: 140.91,
119+
neodyymi: 144.24,
120+
prometium: 145,
121+
samarium: 150.36,
122+
europium: 151.96,
123+
gadolinium: 157.25,
124+
terbium: 158.93,
125+
dysprosium: 162.50,
126+
holmium: 164.93,
127+
erbium: 167.26,
128+
tulium: 168.93,
129+
ytterbium: 173.04,
130+
luteettium: 174.97,
131+
hafnium: 178.49,
132+
tantaali: 180.95,
133+
volframi: 183.84,
134+
renium: 186.21,
135+
osmium: 190.23,
136+
iridium: 192.22,
137+
platina: 195.08,
138+
kulta: 196.97,
139+
elohopea: 200.59,
140+
tallium: 204.38,
141+
lyijy: 207.2,
142+
vismutti: 208.98,
143+
polonium: 209,
144+
astatine: 210,
145+
radon: 222,
146+
francium: 223,
147+
radium: 226,
148+
aktinium: 227,
149+
torium: 232.04,
150+
protaktinium: 231.04,
151+
uraani: 238.03,
152+
neptunium: 237,
153+
plutonium: 244,
154+
amerikium: 243,
155+
kurium: 247,
156+
berkelium: 247,
157+
kalifornium: 251,
158+
einsteinium: 252,
159+
fermium: 257,
160+
mendelevium: 258,
161+
nobelium: 259,
162+
lawrencium: 262,
163+
rutherfordium: 267,
164+
dubnium: 270,
165+
seaborgium: 271,
166+
bohrium: 270,
167+
hassium: 277,
168+
meitnerium: 276,
169+
darmstadtium: 281,
170+
roentgenium: 280,
171+
copernicium: 285,
172+
nihonium: 284,
173+
flerovium: 289,
174+
moscovium: 288,
175+
livermorium: 293,
176+
tennessine: 294,
177+
oganessoni: 294,
178+
};
179+
180+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
chrome.commands.onCommand.addListener(function (command) {
2+
if (command === "openPopup") {
3+
const popupURL = chrome.extension.getURL('popup.html');
4+
chrome.windows.create({
5+
url: popupURL,
6+
type: 'popup', // This should open it as a browser popup
7+
width: 500,
8+
height: 180,
9+
});
10+
}
11+
});
29.5 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"manifest_version": 2,
3+
"name": "Chemistry Extension",
4+
"version": "1.3",
5+
"permissions": [
6+
"activeTab",
7+
"tabs",
8+
"storage",
9+
"clipboardWrite"
10+
11+
],
12+
"commands": {
13+
"openPopup": {
14+
"suggested_key": {
15+
"default": "Alt+U",
16+
"mac": "Command+U"
17+
},
18+
"description": "Opens Popup"
19+
}
20+
},
21+
"background": {
22+
"scripts": ["background.js"],
23+
"persistent": false
24+
},
25+
"browser_action": {
26+
"default_popup": "popup.html"
27+
}
28+
}
29+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Chemistry extension</title>
6+
<link rel="stylesheet" href="styles.css" >
7+
</head>
8+
<body>
9+
10+
11+
<div id="content">
12+
<input type="text" id="searchField">
13+
14+
15+
<br>
16+
17+
<h1 id="result"></h1>
18+
</div>
19+
20+
21+
<script src="app.js"></script>
22+
23+
24+
25+
26+
</body>
27+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
body {
2+
background-color: rgb(rgb(198, 214, 205), green, blue);
3+
width: 200px;
4+
max-width: 500px;
5+
}
6+
7+
#content {
8+
display: grid;
9+
place-items: center;
10+
}

0 commit comments

Comments
 (0)