-
−1
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
export function toNumber(numeric) {
if (Number(numeric) === 0) { // Функция проверит, переданное её значение на число.
return true
} else if (!Number.isInteger(Number(numeric))) {
return false
} else {
return +numeric
}
}
Функция проверит, переданное её значение на число.
DKVitol,
20 Ноября 2018
-
+1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
export function doFilters(global, value) {
let filterListGeo, filterListStatus
const timeLife = global.selectedFilters.ttl // Функция настройки параметров фильтра. По каждому полю проходит проверка: либо фильтр отсутсвует, либо его настройки соовтетсвуют пользовательским.
const timeStart = global.selectedFilters.tts
const rate = global.selectedFilters.startRate
const shippingDate = new Date(formatDate(value.dateFrom, 'MM.DD.YYYY'))
const unloadDate = new Date(formatDate(value.dateTo, 'MM.DD.YYYY'))
const shippingDateFrom = new Date(global.dateFromInterval[0])
const shippingDateTo = new Date(global.dateFromInterval[1])
const unloadDateFrom = new Date(global.dateToInterval[0])
const unloadDateTo = new Date(global.dateToInterval[1])
if (global.strainer) {
filterListGeo = global.strainer.geozoneFrom
filterListStatus = global.strainer.status
}
return ((!global.selectedFilters) || (!timeLife) || (!timeLife.from && !timeLife.to) || (value.ttl >= timeLife.from && value.ttl < timeLife.to) || (!timeLife.to && value.ttl > timeLife.from)) &&
((!global.selectedFilters) || (!timeStart) || (!timeStart.from && !timeStart.to) || (value.ttl >= timeStart.from && value.ttl < timeStart.to) || (!timeStart.to && value.ttl > timeStart.from)) &&
((!global.orderId) || (!global.orderId.length || String(value.orderId).substr(0, global.orderId.length) === global.orderId)) &&
((!rate.from && !rate.to) || (value.startRate >= rate.from && value.startRate <= rate.to)) &&
((!filterListGeo) || (filterListGeo.every(item => !item.checked)) || (filterListGeo.find(item => item.name === value.geozoneFrom).checked)) &&
((!filterListStatus) || (filterListStatus.every(item => !item.checked)) || (filterListStatus.find(item => item.name === value.status).checked)) &&
((!global.dateFromInterval.length) || (shippingDate >= shippingDateFrom && shippingDate <= shippingDateTo)) &&
((!global.dateToInterval.length) || (unloadDate >= unloadDateFrom && unloadDate <= unloadDateTo))
}
Функция настройки параметров фильтра. По каждому полю проходит проверка: либо фильтр отсутсвует, либо его настройки соовтетсвуют пользовательским.
DKVitol,
20 Ноября 2018
-
0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
export function transformDate(time) {
let hours, minutes // Функция преобразует переаднную её дату в формат "00:00:00".
const second = '00'
if (time.getHours() < 10) { hours = '0' + time.getHours() } else { hours = time.getHours() }
if (time.getMinutes() < 10) { minutes = '0' + time.getMinutes() } else { minutes = time.getMinutes() }
return hours + ':' + minutes + ':' + second
}
Функция преобразует переаднную её дату в формат "00:00:00".
DKVitol,
20 Ноября 2018
-
−2
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
function okruglik(num) {
if(isNaN(num)){
summi = summi;
} else {
summi = Math.floor(num);
}
return summi;
}
Притом функция нигде не используется и переменная не объявлена
unicorn,
10 Ноября 2018
-
+1
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
var btn_checkAll = document.getElementById('checkAll');
if (btn_checkAll) {
btn_checkAll.addEventListener('click', checkAll);
}
var inputTagsArray = [];
function getInputTags() {
inputTagsArray = document.getElementsByTagName('input');
inputTagsArray = Array.prototype.slice.call(inputTagsArray);
}
function getArray(action) {
getInputTags();
var checkedInputTagsArray = [];
inputTagsArray.forEach(function(element) {
if (element.getAttribute('id')) {
if (element.checked) {
checkedInputTagsArray.push(element.getAttribute('id'));
}
}
});
if (!checkedInputTagsArray[0]) {
alert("Не было выбрано ни одного изображения");
return false;
}
else {
if (confirm("Вы уверены что хотите совершить данное действие?")) {
//в пхп есть гет-метод, который удаляет картиночки по ид.
//надо передавать ид, но я неосилятор и не осили аякс, поэтому
//вместо нормального метода, принимающего массивом ид картиночек постом
//я делаю это:
location.href = "/products/" + action + "/?id=" + checkedInputTagsArray.join("_");
}
else {
return false;
}
}
}
function checkAll() {
getInputTags();
inputTagsArray.forEach(function(element){
if (element.getAttribute('id')) {
if (element.checked) {
element.checked = false;
}
else {
element.checked = true;
}
}
});
}
function deleteChecked() {
getArray("imagedelete");
}
function showHideChecked() {
getArray("show-hide");
}
в пхп есть гет-метод, который удаляет картиночки по ид.
надо передавать ид, но я неосилятор и не осили аякс, поэтому
вместо нормального метода, принимающего массивом ид картиночек постом
я делаю это:
wowwtfisthatworking,
31 Октября 2018
-
+3
- 1
[ '\uD83D\uDC14', '\uD83E\uDD5A' ].sort()
Unicode порешал
https://twitter.com/aBagorn/status/1051286652663025664
Оригинал не влез, ибо:
Application was halted by an exception.
Debug-mode is off.
Elvenfighter,
17 Октября 2018
-
0
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
//<?php
$is_php = !'0';
if ($is_php) {
echo(PHP_EOL);
perevedi_na_php();
} else {
console.log('//');
perevedi_na_js();
}
function perevedi_na_php() {
echo('Hello, "PHP"!' . PHP_EOL);
}
function perevedi_na_js() {
console.log('Hello, "PHP"!');
}
Perevedi_na_PHP,
04 Октября 2018
-
−3
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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 Comment Highlighter
// @description Подсвечивает новые комментарии
// @include *://govnokod.ru/*
// @include *://www.govnokod.ru/*
// @version 2.1
// @grant none
// ==/UserScript==
(function() {
function updateState(data, lastPID, updater) {
// use `cid = 0` to enable highlighting comments in unvisited posts
// use `cid = Infinity` to disable highlighting in unvisited posts
var out, idx, pid, i = 0, cid = 0; // here
while(i < data.length) {
idx = i;
pid = data.charCodeAt(i++);
if(pid & 0x8000) {
pid &= 0x7fff;
pid <<= 16;
pid |= data.charCodeAt(i++);
}
if(pid == lastPID) {
cid = data.charCodeAt(i++) << 16 | data.charCodeAt(i++);
break;
} else {
i += 2;
}
}
data = pid == lastPID ? data.substring(0, idx) + data.substring(i) : data;
var lastCID = updater(cid);
if(isFinite(lastPID) && lastPID >= 0 && lastPID < 0x80000000) {
data += (lastPID >= 0x8000 ? String.fromCharCode(0x8000 | lastPID >> 16) : '') +
String.fromCharCode(lastPID & 0xffff) + String.fromCharCode(lastCID >> 16) +
String.fromCharCode(lastCID & 0xffff);
}
return data;
}
function commentID(comment) {
var commentLink = comment.querySelector('a.comment-link');
return Number(commentLink.href.match(/comment(\d+)$/)[1]);
}
function updateComments(prevCID) {
var comments = document.querySelectorAll('.entry-comment-wrapper');
var lastCID = prevCID;
for(var i=0; i<comments.length; ++i) {
var comment = comments[i];
var cid = commentID(comment);
if(cid <= prevCID) continue;
if(cid > lastCID) lastCID = cid;
comment.classList.add('new');
}
return lastCID;
}
var post = location.pathname.match(/^\/(\d+)/);
if(!post) return;
var PARAM = '8a9bd32e-20bc-42c7-bcdd-b65bb1fc2d0b-visited2';
var postID = +post[1];
var oldState = localStorage.getItem(PARAM) || '';
var newState = updateState(oldState, postID, updateComments);
localStorage.setItem(PARAM, newState);
})();
Битоёбство в "JS".
https://github.com/1024--/govnokod.ru-userscripts/blob/master/highlight-new.user.js
> use `cid = Infinity` to disable highlighting in unvisited posts
Не работает.
При следующем открытии все помечаются как не прочтённые.
Пофиксил так:
function updateComments(prevCID, highlightUnvisited=false) {
var comments = document.querySelectorAll('.entry-comment-wrapper');
var lastCID = prevCID;
for(var i=0; i<comments.length; ++i) {
var comment = comments[i];
var cid = commentID(comment);
if(cid <= prevCID) continue;
if(cid > lastCID) lastCID = cid;
if (!highlightUnvisited && prevCID === 0) continue;
comment.classList.add('new');
}
return lastCID;
}
guestinxo,
02 Октября 2018
-
−2
- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
<a class="callformtrigger" href="http://#ck_callback_button"><!-- container box --></a>
<script>
(function(){
try{
var el = $("a.callformtrigger");
var hash = el.attr("href");
hash = hash.replace("http://", "");
el.attr("href", hash);
}
catch(e)
{
/** **/
}
})();
</script>
вместо того, чтобы поправить данный url в исходниках, был применен данный способ
turbosnail,
26 Сентября 2018
-
0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
NaN = 5;
console.log(NaN); // NaN
undefined = 5;
console.log(undefined); // undefined
0 = 5; // Uncaught ReferenceError: Invalid left-hand side in assignment
guestinxo,
21 Сентября 2018