Last active
August 29, 2015 14:21
-
-
Save zackad/5b02eac8d2de947d14ab to your computer and use it in GitHub Desktop.
[stuck] get 1st post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Kaskus TS Tagger | |
// @namespace zackad's script | |
// @version 0.6 | |
// @description Give TS kaskus a Tag | |
// @grant GM_addStyle | |
// @include http://m.kaskus.co.id/* | |
// @include http://fjb.m.kaskus.co.id/* | |
// @include /^https?://(www|fjb).kaskus.co.id/(thread|lastpost|post|show_post|product|group/discussion)/*/ | |
// @require http://code.jquery.com/jquery-1.10.1.min.js | |
// @copyright 2015, zackad | |
// ==/UserScript== | |
/* | |
CHANGELOG | |
v0.5 | |
- [bug] image not load | |
v0.4 | |
- fjb support | |
v0.3 | |
- tag color [thanks : ahmad13] | |
*/ | |
$(document).ready(function(){ | |
var DEBUG = 0; | |
var tID = $('#thread_id'); | |
tID = tID.attr('value'); | |
// clog(tID); | |
//style edit sesuai selera | |
var globalStyle = '' | |
+'<style type="text/css">' | |
+'.thread-starter {background-color:black; color:white!important; border:1px solid orange!important;}' | |
+'.thread-starter .fn, .thread-starter .permalink {color:white!important}' | |
+'.thread-starter-desk {border:1px solid sandybrown!important;}' | |
+'.thread-starter-desk .entry-head {background-color:darkorange!important;}' | |
+'.thread-starter-desk .entry-body {border-left:1px solid sandybrown!important;}' | |
+'.thread-starter-desk .entry-footer {border-top:1px solid sandybrown;}' | |
+'.thread-starter-first {border:1px solid sandybrown!important;}' | |
+'.thread-starter-first .entry-head {background-color:darkorange!important;}' | |
+'.thread-starter-first .entry-body {border-left:1px solid sandybrown!important;}' | |
+'.thread-starter-first .entry-footer {border-top:1px solid sandybrown;}' | |
+'</style>' | |
; | |
//silahkan edit sesuka ente | |
var mTS = '<span style="color:darkorange; font-weight:bold;"><b>[TS]</b></span>'; | |
var dTS = '<span><b style="color:#F5981D;">Thread</b><b style="color:#1998ed;"> Starter</b></span>'; | |
var fTS = '<span style="font-size:24px;"><b style="color:#F5981D;">Thread</b><b style="color:#1998ed;"> Starter</b></span>'; | |
var juragan = '<span><b style="color:#1998ed;">Juragan</b></span>'; | |
var tsContainer = '' | |
+'<div id="ts" class="ts" style="display:none;"></div>' | |
; | |
$('body').prepend(tsContainer); | |
$('head').append(globalStyle); | |
var host = window.location.host; | |
if (isFJB()) | |
var ajaxURL = 'http://'+host+'/product/'+ tID; | |
else var ajaxURL = 'http://'+host+'/thread/'+ tID; | |
//let's call the ajax | |
if(window.location.href.indexOf('m.kaskus.co.id') > -1){ | |
$.ajax({ | |
url: ajaxURL, //'http://m.kaskus.co.id/thread/' + tID, | |
dataType: 'html', | |
success: function(response){ | |
$('.ts').html(jQuery(response).find('.usr .fn').html()); | |
var a = $('.ts').text(); | |
clog('ts =' + a); | |
var poster = $('.author .fn'); | |
poster.each(function(){ | |
var parent = $(this).parent().parent().parent(); | |
var user = $(this); | |
// clog($(this).text()); | |
if($(this).text() == a){ | |
$(parent).addClass('thread-starter'); | |
$(parent).parent().css('border','1px solid orange'); | |
$(user).after(mTS); | |
} | |
}); | |
if(poster == a){ | |
$('.author').addClass('thread-starter'); | |
} | |
} | |
}); | |
} | |
// desktop version | |
$.ajax({ | |
url: ajaxURL, //'http://'+host+'/thread/' + tID, | |
dataType: 'html', | |
success: function(response){ | |
if(isFJB()) $('.ts').html(jQuery(response).find('.seller-info .seller-detail-info .username a').html()); | |
else $('.ts').html(jQuery(response).find('.postlist .author .user-details .nickname').html()); | |
var a = $('.ts').text(); | |
clog('ts desktop ='+ a); | |
var poster = $('.postlist .author .user-details .nickname'); | |
// clog(poster); | |
poster.each(function(){ | |
var parent = $(this).parent().parent().parent().parent().parent();//.parent();//..sUntil('.col-xs-12'); | |
var user = $(this);//.text(); | |
var userDetail = $(this).parent().parent(); | |
if(user.text() == a){ | |
// STUCK HERE | |
if($(parent).has('.entry-head a[name="1"]')){ | |
$(parent).addClass('thread-starter-first'); | |
$(user).append(mTS); | |
clog(userDetail); | |
if(isFJB()) dTS = juragan; | |
$('.thread-starter-first .user-option').prepend(fTS); | |
}else{ | |
$(parent).addClass('thread-starter-desk'); | |
$(user).append(mTS); | |
clog(userDetail); | |
if(isFJB()) dTS = juragan; | |
$(userDetail).children('.user-info').before(dTS); | |
} | |
} | |
}); | |
} | |
}); | |
function isFJB(){ | |
if(window.location.host == 'fjb.kaskus.co.id' || window.location.host == 'fjb.m.kaskus.co.id') return true; | |
else return false; | |
} | |
function clog(x){ | |
if(!DEBUG) return; | |
console && console.log && console.log(x); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
can't retrieve element inside #ts