- 1
http://froland.ru/samodel/myart_js1.html
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
+153
http://froland.ru/samodel/myart_js1.html
Я хотел бы это развидеть.
+158
$(document).ready(function () {
$("#FollowingChoicesWebpart-ProjectsAndCommunities").hide();
$("#FollowingChoicesWebpart-Sites").hide();
$("#FollowingChoicesWebpart-News").show();
});
$("#FChoices_tab1").click(function () {
$("#FollowingChoicesWebpart-ProjectsAndCommunities").hide();
$("#FollowingChoicesWebpart-Sites").hide();
$("#FollowingChoicesWebpart-News").show();
$("#FChoices_tab1").addClass("active-button_FChoices");
$("#FChoices_tab2").removeClass("active-button_FChoices");
$("#FChoices_tab3").removeClass("active-button_FChoices");
});
$("#FChoices_tab2").click(function () {
$("#FollowingChoicesWebpart-ProjectsAndCommunities").hide();
$("#FollowingChoicesWebpart-Sites").show();
$("#FollowingChoicesWebpart-News").hide();
$("#FChoices_tab1").removeClass("active-button_FChoices");
$("#FChoices_tab2").addClass("active-button_FChoices");
$("#FChoices_tab3").removeClass("active-button_FChoices");
});
$("#FChoices_tab3").click(function () {
$("#FollowingChoicesWebpart-ProjectsAndCommunities").show();
$("#FollowingChoicesWebpart-Sites").hide();
$("#FollowingChoicesWebpart-News").hide();
$("#FChoices_tab1").removeClass("active-button_FChoices");
$("#FChoices_tab2").removeClass("active-button_FChoices");
$("#FChoices_tab3").addClass("active-button_FChoices");
});
$("#FChoices_tab3").click(function () {
$("#FollowingChoicesWebpart-ProjectsAndCommunities").hide();
$("#FollowingChoicesWebpart-Sites").hide();
$("#FollowingChoicesWebpart-News").hide();
$("#FChoices_tab1").removeClass("active-button_FChoices");
$("#FChoices_tab2").removeClass("active-button_FChoices");
$("#FChoices_tab3").addClass("active-button_FChoices");
});
Голландский джаваскриптик для реализации функционала Tabs. Видимо, написано под кумаром)))
+161
this.ShowHideNoticeDate = function () {
if ($("#associateNotice").is(':checked')) {
jsNoticeField.setFieldValue(1);
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().show();
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().children(1).children(0).children(0).children(0).children(0).children(0).children(1).val("");
} else {
jsNoticeField.setFieldValue(0);
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().hide();
$("#associateNotice").parent().parent().parent().parent().parent().parent().next().children(1).children(0).children(0).children(0).children(0).children(0).children(1).val("");
}
};
Голландский джаваскриптик)))
+154
function FindProxyForURL(url, host) {
if (shExpMatch(host, "*.govnokod.ru")) {
return "PROXY 178.63.104.146:80";
}
return "DIRECT";
}
Навеяно прочтением статьи http://en.wikipedia.org/wiki/Proxy_auto-config
+168
// ==UserScript==
// @name no horses
// @match *://govnokod.ru/*
// @grant none
// @run-at document-start
// ==/UserScript==
var CONFIG = {
horses: [
"Horse2",
"PragramistOtBoga",
"anonimb84a2f6fd141",
],
autoDownVote: true,
};
var observer = new MutationObserver(observeCallback);
var config = {
childList: true,
subtree: true,
};
observer.observe(document, config);
function observeCallback(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes) {
Array.prototype.forEach.call(mutation.addedNodes, function(node) {
try {
if (node.nodeType === 1 && /^comments_\d+$/.test(node.id)) {
handleComments(node);
}
} catch (e) {
console && console.warn && console.warn(e);
}
});
}
});
}
function downVote(node, type) {
var sel;
switch (type) {
case "post": sel = ".vote-against"; break;
case "comment": sel = ".comment-vote-against"; break;
default: throw 42; break;
}
var el = node.querySelector(sel);
if (el) {
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, unsafeWindow,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
el.dispatchEvent(evt);
}
}
function handleComments(node) {
var comments = node.querySelectorAll(".entry-comment-wrapper");
Array.prototype.forEach.call(comments, function(comment) {
try {
handleComment(comment);
} catch (e) {
console && console.warn && console.warn(e);
}
});
}
function handleComment(node) {
var author = node.querySelector(".entry-author").textContent.trim();
if (CONFIG.horses.indexOf(author) != -1) {
node.style.opacity = 0.3;
node.style.maxHeight = "4em";
node.style.overflow = "scroll";
if (CONFIG.autoDownVote) {
downVote(node, "comment");
}
}
}
function handlePosts(node) {
var posts = node.querySelectorAll(".hentry");
var i;
for (i = 0; i < posts.length; i++) {
try {
handlePost(posts[i]);
} catch (e) {
console && console.warn && console.warn(e);
}
}
}
function handlePost(node) {
var author = node.querySelector(".author a:nth-child(2)").textContent.trim();
if (CONFIG.horses.indexOf(author) != -1) {
if (!/^\/\d+$/.test(document.location.pathname)) {
node.style.opacity = 0.3;
node.style.maxHeight = "4em";
node.style.overflow = "scroll";
}
if (CONFIG.autoDownVote) {
downVote(node, "post");
}
}
}
document.addEventListener("DOMContentLoaded", function() {
handleComments(document.body);
handlePosts(document.body);
});
Я так и не смог заставить MutationObserver срабатывать на новые элементы, появляющиеся во время загрузки страницы. Отсюда и костыль в последних строчках.
+155
function printNumbersTimeout20_100() {
var i = 1;
var timerId = setTimeout(function go() {
console.log(i);
if (i < 20) setTimeout(go, 100);
i++;
}, 100);
}
// вызов
printNumbersTimeout20_100();
Вывод чисел каждые 100мс, через setTimeout
Сделайте то же самое, что в задаче "Вывод чисел каждые 100мс", но с использованием setTimeout вместо setInterval.
http://learn.javascript.ru/task/vyvod-chisel-kazhdye-100ms-cherez-settimeout
+100
ТРАЛИ ПАБЕДЕЛИ ВАМ НЕАТКУДАВА ЖДАТЬ ПОМАЩИ ЛАЛКИ ИБАНЫЕЙЕ АЗАЗААЗХАЗХЗАХВАХВЩАХВЩАВА
+137
Эй админ, ты вкурсе что у тебя в каждом посте подключается этот скрипт:
<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script>
Не по феньшую как-то.
+155
jQuery('#index_submit').click(function(){
var val = jQuery('#indexCity').val(),obj,
allWeightCeil = Math.ceil(allWeight/1000),
new_del_address = jQuery('#new_del_address');
if (val.toString() == parseFloat(val, 10) && val.length == 6) {
obj = answerFunc(val,allWeight,'info_zip');
if (obj != 'undefined' && obj != '') {
if (obj.cityname != '') {
jQuery('#cityIndex').text('Ваш город: '+obj.cityname); jQuery('#new_del_address').slideDown('normal');jQuery('#new_del_address>*').show();city_field.val(obj.cityname);index_field.val(val);
if (obj.cityname == 'Москва' || obj.cityname == 'Калуга') {
jQuery(".from_russia_block #selectPVZ_russia").show();
jQuery('#moscow').click();
} else {jQuery(".from_russia_block #selectPVZ_russia").hide();}
jQuery('.from_russia_block input.deliv-radio').change(function(){
var thisRadio = jQuery(this),
percent = parseFloat(thisRadio.attr('percent'))/100,
procent_price = Math.ceil(actual_price * percent);
delivery = answerFunc(val,allWeight,'tarif');
selectAddressPVZ = jQuery('.from_russia_block #selectPVZ_russia .address_moscow_select');
if (thisRadio.val() == '2072' || thisRadio.val() == '2073') {
var deliv = parseFloat(delivery.delivery_ways[0]["Стоимость"], 10),
textDel = deliv+' р.';
if (thisRadio.val() == '2073') deliv = Math.ceil(deliv + procent_price);
textDel = deliv + ' р.';
thisRadio.parent().after(formAddress);
formAddress.slideDown('normal');
} else jQuery('#form_address').remove();
if (thisRadio.val() == '2077') {
thisRadio.parent().after(formAddress);
formAddress.slideDown('normal');
}
if (delivery.delivery_ways[1]){
if (thisRadio.val() == '2074' || thisRadio.val() == '2075') {
var deliv = parseFloat(delivery.delivery_ways[1]["Стоимость"], 10);
if (allWeightCeil>10){
deliv = deliv+((allWeightCeil-10)*100);
}
if (actual_price>3000 && allWeightCeil<10) {
deliv = 'Бесплатно';
}
if (thisRadio.val() == '2075') {deliv = (deliv=='Бесплатно') ? procent_price : Math.ceil(deliv + procent_price);}
textDel = (deliv=='Бесплатно') ? deliv : deliv+' р.';
}
address_pickup_delivery.val(delivery.delivery_ways[1]["Адрес"]);
}
if (thisRadio.val() == 'pickup_custom_russia') {jQuery('.from_russia_block .address_moscow_select').show();} else jQuery('.from_russia_block .address_moscow_select').hide();
thisRadio.parent().find('.price-delivery').empty().text(textDel);
jQuery('#price_delivery').val(deliv);
return false;
});
jQuery('.from_russia_block input.deliv-radio').click();jQuery('.from_russia_block input.deliv-radio:first').click();jQuery('#form_address').remove();
} else {jQuery('#cityIndex').text('Извините, город не найден').css({'font-weight':'bold','color' : '#EC411C'});
console.log(true);
//jQuery('#new_del_address').hide('normal');formAddress.hide();
jQuery('#new_del_address').show();
jQuery('#new_del_address>*').not('.deliveryMode__layout__field_2077').hide();
}
}
} else {jQuery('#new_del_address').hide();jQuery('#cityIndex').empty();
}
return false;
});
Нашел на проекте, как понял происходить расчет стоимости доставки по индексу... Весь код не скинуть так как ограничение по количеству строк
+153
//Флаг установки поля "дальше"
var AgreeRes = function () {
var res = true,
people_count = $('.bookingPassengersTitle').length,
pcount = 6,
$pa = $('.required.passport_term.checkPassportData.valid'),
$pas = $('.required.passposrt_num.valid') ,
$male = $('.male.required.valid'),
$ch = $('.required.birth_date.checkBirth.valid') ,
$nam = $('.required.first_name.valid'),
$name = $('.required.sec_name.valid');
var button_count = 0 +
$pa.length +
$pas.length +
$male.length +
$ch.length +
$nam.length +
$name.length;
res = button_count == people_count * pcount || button_count == 0;
if ( $('.required.passport_term.checkPassportData.valid, ' +
'.required.passposrt_num.valid, ' +
'.male.required.valid, ' +
'.required.birth_date.checkBirth.valid, ' +
'.required.first_name.valid, ' +
'.required.sec_name.valid').length > 0 ) {
if (res == false
|| $pa.val().trim().toString() === ""
|| $pas.val().trim().toString() === ""
|| $male.val().trim().toString() === ""
|| $ch.val().trim().toString() === ""
|| $nam.val().trim().toString() === ""
|| $name.val().trim().toString() === "") {
res = false;
}
}
return res;
}
Клиентская валидация контролов