Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name SceneSource Category Filters
- // @namespace http://127.0.0.1/
- // @description Allows you to filter content by individual categories (only works with Shadowness).
- // @include http://www.scnsrc.net/*
- // ==/UserScript==
- var $ = unsafeWindow['jQuery'];
- var categories = [];
- $('ul.categories > li.cat-item > a:first-child').each(function() {
- categories.push($(this).text());
- });
- var filters = new Array(categories.length);
- if (document.cookie.length > 0) {
- var start = document.cookie.indexOf('filters=') + 8;
- if (start > 7) {
- var end = document.cookie.indexOf(';', start);
- if (end == -1)
- end = document.cookie.length;
- var str = unescape(document.cookie.substring(start, end));
- if (str.length == filters.length) {
- for (var i = 0; i < filters.length; i++) {
- if ((filters[i] = (str.charAt(i) == '1' ? '1' : '0')) == 1) {
- toggle(categories[i], 1);
- }
- }
- }
- }
- }
- if (filters[filters.length -1] === undefined) {
- for (var i = 0; i < filters.length; i++) {
- filters[i] = '0';
- }
- }
- $('ul.filters').each(function() {
- $(this).empty();
- for (var i = 0; i < categories.length; i++) {
- var str = filters[i] == '0' ? 'Disable' : 'Enable';
- $(this).append($('<li />').css({
- 'background': 'url("/wp-content/themes/shadowness/images/pip.gif") no-repeat scroll 0 0 transparent',
- 'padding-left': '8px'}).append($('<a />').text(str + ' ' + categories[i]).attr('id', 'filter_' + i).click(function(event) {
- event.preventDefault();
- var id = $(this).attr('id').substring(7);
- var category = $(this).text().substring($(this).text().indexOf(' ') + 1);
- filters[id] = filters[id] == '0' ? '1' : '0';
- $(this).text((filters[id] == '0' ? 'Disable' : 'Enable') + ' ' + category);
- toggle(category, filters[id]);
- document.cookie = 'filters=' + filters.join('') + ';expires=0';
- })));
- }
- });
- function toggle(category, hide) {
- $('div.post').each(function() {
- var post = $(this);
- $('div.cat.meta span.left a[rel=category tag]', post).each(function() {
- if (category == $(this).text()) {
- post.css('display', hide == '1' ? 'none' : '');
- }
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement