-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
75 lines (65 loc) · 3.66 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// ==UserScript==
// @name Tehran air pollution
// @name:en Tehran air pollution
// @name:fa آلودگی هوای تهران
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Tehran air pollution script. saves default preferences.
// @description:en Tehran air pollution script. saves default preferences.
// @description:fa شاخص آلودگی هوای تهران - تنظیمات شخصی
// @author Arman Karimi
// @match https://airnow.tehran.ir/home/OnlineAQI.aspx
// @icon https://www.google.com/s2/favicons?domain=tehran.ir
// @grant none
// @license MIT
// @homepageURL https://github.com/iArmanKarimi/TehranAirPollution-SaveDefaults-GFScript/
// ==/UserScript==
(function() {
'use strict';
var LAST_STATION_NUM_LS = 'last-station'
var COLLAPSE_BUTTON_MAP_LS = 'map-collapsed'
var COLLAPSE_BUTTON_CHART_LS = 'chart-collapsed'
var STATION_DEFAULT_CB_CHECKED_LS = 'station-default-checkbox-checked'
var stations_text_el = document.getElementById('ContentPlaceHolder1_lblStation')
var stations_select_el = document.getElementById('ContentPlaceHolder1_ddlStation')
stations_select_el.addEventListener('change', function () {
localStorage[LAST_STATION_NUM_LS] = this.value.toString()
})
var clue_collapse_map_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(2) > div > div.box-body")
var clue_collapse_chart_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(1) > div > div.box-body")
window.addEventListener("beforeunload", function () {
localStorage[COLLAPSE_BUTTON_MAP_LS] = clue_collapse_map_el.style.display === 'none'
localStorage[COLLAPSE_BUTTON_CHART_LS] = clue_collapse_chart_el.style.display === 'none'
}, false);
if (localStorage[STATION_DEFAULT_CB_CHECKED_LS] === 'true' &&
stations_select_el.value !== localStorage[LAST_STATION_NUM_LS].toString()) {
stations_select_el.value = localStorage[LAST_STATION_NUM_LS]
stations_select_el.onchange()
}
var default_cb_el = document.createElement('input')
var default_cb_lbl_el = document.createElement('label')
stations_text_el.after(default_cb_el)
stations_text_el.after(default_cb_lbl_el)
default_cb_el.setAttribute('type', 'checkbox')
default_cb_el.setAttribute('name', 'def_station_btn_cb')
default_cb_lbl_el.setAttribute('for', 'def_station_btn_cb')
default_cb_lbl_el.textContent = 'پیش فرض'
default_cb_el.checked = localStorage[STATION_DEFAULT_CB_CHECKED_LS] === 'true'
default_cb_el.addEventListener('change', function () {
localStorage[STATION_DEFAULT_CB_CHECKED_LS] = default_cb_el.checked
})
var map_btn_icon_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(2) > div > div.box-header.with-border > div > button > i")
var chart_btn_icon_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(1) > div > div.box-header.with-border > div > button > i")
var map_box_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(2) > div")
var chart_box_el = document.querySelector("#form1 > div.wrapper > div > div > section.content > div:nth-child(2) > div:nth-child(1) > div")
if (localStorage[COLLAPSE_BUTTON_MAP_LS] === 'true') {
map_box_el.className += ' collapsed-box'
map_btn_icon_el.className = 'fa fa-plus'
clue_collapse_map_el.style.display = 'none'
}
if (localStorage[COLLAPSE_BUTTON_CHART_LS] === 'true') {
chart_box_el.className += ' collapsed-box'
chart_btn_icon_el.className = 'fa fa-plus'
clue_collapse_chart_el.style.display = 'none'
}
})();