Last active
August 29, 2015 13:57
-
-
Save shenmao1989/9383154 to your computer and use it in GitHub Desktop.
xx-feed
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
!function(){ | |
if($('#J_Xx_Feed_Collect').length > 0){ | |
return; | |
} | |
var day = /(\d{8})/.exec(location.href); | |
day = day[1]; | |
var today = Math.floor((+ new Date()) / ( 24 * 60 * 60 * 1000)) * ( 24 * 60 * 60 * 1000); | |
var currentDay = new Date(day.substr(0,4) + '-' + day.substr(4,2) + '-' + day.substr(6,2)); | |
var interest = /interest=([^\&]*)/.exec(location.href); | |
interest = decodeURIComponent(interest[1]); | |
var localData = getLocal(); | |
if(!localData[day]){ | |
localData[day] = {}; | |
} | |
if(!localData[day][interest]){ | |
localData[day][interest] = []; | |
} | |
var currentDayData = localData[day][interest]; | |
var collectBox = $('<div id="J_Xx_Feed_Collect" style="position: fixed; top: 0; left: 100%;margin-left: -240px;margin-top: 10px;font-size: 12px;overflow-y: scroll;max-height: 480px;" class="alert alert-success"><p>日期:'+day+'</p></div>'); | |
$('body').append(collectBox); | |
var title = $(collectBox).find('p'); | |
var list; | |
$.each(localData[day], function(k, v){ | |
var item = $('<p><b>'+k+'</b></p><ul style="list-style: none;padding-left: 0;"></ul>'); | |
$(title).after(item); | |
var dataList = item[1]; | |
$.each(v, function(i, id){ | |
if(id){ | |
$(dataList).append('<li>' + id + '</li>'); | |
} | |
}); | |
if(k == interest){ | |
list = dataList; | |
} | |
}); | |
if(today - currentDay != 24 * 60 * 60 * 1000){ | |
$(title).before('<p><span class="label label-warning">注意当前页面不是昨天的数据</span></p></br>'); | |
} | |
function calc(){ | |
$(list).children().remove(); | |
var ids = []; | |
$('.J_Selected_Feed').each(function(i, item){ | |
if($(item).hasClass('btn-success')){ | |
var id = $(item).data('feedid'); | |
if(id){ | |
ids.push(id); | |
$(list).append('<li>' + id + '</li>'); | |
} | |
} | |
}); | |
localData[day][interest] = currentDayData = ids; | |
setLocal(localData); | |
} | |
$('.col-md-10').each(function(i, item){ | |
var parent = $(item); | |
var feedid = $(parent).find('a')[0]; | |
feedid = /feedId=(\d+)/.exec(feedid.href) | |
feedid = feedid[1]; | |
if(!feedid){ | |
return; | |
} | |
var btn = $(' <button type="button" data-feedid="' + feedid + '" class="J_Selected_Feed btn btn-sm btn-danger">标记为不符合</button>'); | |
$(item).before(btn); | |
$(btn).click(function(){ | |
if($(this).hasClass('btn-danger')){ | |
//加入到 | |
$(this).removeClass('btn-danger'); | |
$(this).addClass('btn-success'); | |
$(this).text('取消标记'); | |
}else{ | |
//取消到 | |
$(this).addClass('btn-danger'); | |
$(this).removeClass('btn-success'); | |
$(this).text('标记为不符合'); | |
} | |
calc(); | |
}); | |
if($.inArray(feedid * 1, currentDayData) != -1){ | |
$(btn).removeClass('btn-danger'); | |
$(btn).addClass('btn-success'); | |
$(btn).text('取消标记'); | |
} | |
}); | |
function getLocal(){ | |
var data = window.localStorage.xxFeeds; | |
try{ | |
data = JSON.parse(data); | |
}catch(e){ | |
return {}; | |
} | |
return data; | |
} | |
function setLocal(d){ | |
var tmp_data = { | |
'20130203': { | |
'分类1': [123,234,455], | |
'分类2': [123,234,455], | |
'分类3': [123,234,455] | |
} | |
} | |
window.localStorage.xxFeeds = JSON.stringify(d); | |
} | |
}(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment