hehe :)
目前為
// ==UserScript==
// @name prodpad
// @namespace proximis
// @version 1.2
// @description hehe :)
// @author teles
// @match https://app.prodpad.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
var sheet = (function() {
var style = document.createElement("style");
style.appendChild(document.createTextNode(""));
document.head.appendChild(style);
return style.sheet;
})();
sheet.insertRule(".roadmap-column__body { display: none; }", 0);
sheet.insertRule(".roadmap-column-wrapper .roadmap-column { padding-bottom: 0; }", 0);
sheet.insertRule(".pxroadmap { margin-bottom: 100px; }", 0);
sheet.insertRule(".pxms { display: none; }", 0);
sheet.insertRule(".pxload { margin: 30px; }", 0);
sheet.insertRule(".pxidea select { opacity: 0.3; }", 0);
sheet.insertRule(".pnewidea { background: #d9534f; }", 0);
sheet.insertRule(".p037b4910498411e5b90322000a23849c { background: #d9534f; }", 0);
sheet.insertRule(".p037b4f5a498411e5b90322000a23849c { background: #f0ad4e; }", 0);
sheet.insertRule(".p037b50ae498411e5b90322000a23849c { background: #5cb85c; }", 0);
sheet.insertRule(".p037b51da498411e5b90322000a23849c { background: #5cb85c; }", 0);
sheet.insertRule(".p037b5482498411e5b90322000a23849c { background: black; }", 0);
sheet.insertRule(".pxfilter { background: white; position: absolute; top: 10px; right: 120px; height: 42px; width:100px; padding:5px; }", 0);
sheet.insertRule(".pxalert { background: chartreuse; transform: scale(2.0); transition: transform 0.3s; }", 0);
var apiKey = localStorage.getItem('apikey') || '', apiRoadmaps;
if (apiKey) {
$.get('https://api.prodpad.com/v1/roadmaps/10435?apikey='+apiKey).then(function(json){
apiRoadmaps = json;
}, function(){
$('#apikey').show();
});
} else {
var session = JSON.parse(localStorage.getItem('pp_sess'));
$.ajax({
method: 'GET',
url: 'https://api-beta.prodpad.com/api/v2/user/'+session.user.id+'/apikey',
headers: {
'X-API-Token': session.token
}
}).then(function(json){
apiKey = json.apikey;
$('#apikey').val(apiKey);
localStorage.setItem('apikey', $('#apikey').val());
$.get('https://api.prodpad.com/v1/roadmaps/10435?apikey='+apiKey).then(function(json){
apiRoadmaps = json;
}, function(){
$('#apikey').show();
});
}, function(){
$('#apikey').show();
});
}
var api = setInterval(function(){
if (!$('#apikey').length) {
$('.main-head__right').prepend('<li><input id="apikey" placeholder="API Key"/></li>');
$('#apikey').val(apiKey);
$('#apikey').hide();
$('#apikey').keyup(function(){
localStorage.setItem('apikey', $('#apikey').val());
if ($('#apikey').val()) {
apiKey = $('#apikey').val();
$.get('https://api.prodpad.com/v1/roadmaps/10435?apikey='+apiKey).then(function(json){
apiRoadmaps = json;
}, function(){
$('#apikey').show();
});
}
});
} else {
clearInterval(api);
}
}, 200);
var linkify = function(txt) {
return txt.replace(/([^"]https?:\/\/[^\s<\)]*)/g, '<a href="$1">$1</a>');
};
var enhanceRoadmap = function() {
if ($('.pxroadmap').length) {
return;
}
$('select').each(function(){
$('option[value="'+$(this)[0].value+'"]', this).attr('selected', 'selected');
});
var roadmaps = {};
$('.roadmap-column').each(function(){
var version = $('.roadmap-column__head-title', this).text();
roadmaps[version] = [];
$('.card', this).each(function(){
var ideas = {};
var title = $('.card__body .card__title', this).text();
$('.idea-list-item', this).each(function(){
var id = $('.idea-list-item__body-header a', this).attr('href').split('/')[2];
ideas[id] = {
id: id,
num: $('.idea-list-item__body-header', this).text().replace(/IDEA ([0-9]*) .*/, '<a href="/ideas/$1"><strong style="font-size:1.3em">[ <u>$1</u> ]</strong></a>'),
title: $('.idea-list-item__body-header', this).text().replace(/IDEA [0-9]*[ ]+-[ ]+/, ''),
status: $('.idea-list-item__status div:first', this).html(),
class: 'p' + ($('.idea-list-item__status div:first option[selected]', this).attr('value').replace(/-/g, '') || 'newidea')
};
});
roadmaps[version].push({title: title, ideas: ideas});
});
});
console.log(roadmaps);
var html = '<table class="pxroadmap">';
for (var v in roadmaps) {
for(var c=0; c<roadmaps[v].length; c++) {
console.log(v, Object.keys(roadmaps[v][c].ideas).length);
if (Object.keys(roadmaps[v][c].ideas).length) {
html += '<tr class="pxtitle pxms '+btoa(v).replace(/=/g, '')+'"><th colspan="2" style="font-size:1.3em">'+roadmaps[v][c].title+'</th></tr>';
for(var id in roadmaps[v][c].ideas) {
var idea = roadmaps[v][c].ideas[id];
html += '<tr class="pxidea pxidea'+idea.id+' pxms '+btoa(v).replace(/=/g, '')+'">';
html += '<td width="140px" class="idea-list-item__status '+idea.class+'"><div class="input-select small" style="pointer-events: none;">'+idea.status+'</div></td>';
html += '<td style="vertical-align:top">'+idea.num+' - <a href="javascript:;" num="'+$(idea.num).find('u').text()+'" class="pxideatitle" style="font-size:1.2em; color:black">'+idea.title+'</a></td>';
html += '</tr>';
}
}
}
}
html += '</table>';
$('.pxload').hide();
$('.roadmap-main-section').append(html);
$('.roadmap-column__head-title').append('<input placeholder="IDEA..." class="pxfilter"/>');
$('.roadmap-column__head-title').click(function(){
$('.roadmap-column__head-title').css('background', 'none').css('color', 'black').css('padding', '5px');
$('.pxfilter').hide().val('');
$('.pxfilter', this).show().focus();
$(this).css('background', '#337ab7').css('color', 'white');
$('.pxms').hide();
$('.'+btoa($(this).text()).replace(/=/g, '')).show();
});
$('.roadmap-column__head-title:eq(1)').click();
$('.pxfilter').keyup(function(){
var prefix = btoa($(this).parents('.roadmap-column__head-title:first').text()).replace(/=/g, '');
if ($(this).val()) {
$('.'+prefix+'.pxidea, .'+prefix+'.pxtitle').hide();
$('.'+prefix+'.pxidea'+$(this).val()).show();
$('.'+prefix+'.pxidea'+$(this).val()).prevAll('.pxtitle:first').show();
} else {
$('.'+prefix+'.pxidea, .'+prefix+'.pxtitle').show();
}
$('.pxidealoaded').hide();
});
$('.pxideatitle').click(function(){
if ($(this).parents('tr:first').next().hasClass('pxidealoaded')) {
$(this).parents('tr:first').next().toggle();
} else if (!apiKey) {
$('#apikey').addClass('pxalert');
$('.main-head__user .multi-menu').addClass('is-active');
$('.main-head__user .multi-menu__body ul li:first a').css('color', '#25a7d9');
setTimeout(function(){ $('#apikey').removeClass('pxalert'); }, 2000);
} else {
var num = $(this).attr('num');
var rnd = Math.random().toString().substring(3, 10);
$('<tr class="pxidea pxidealoaded"><td></td><td id="pxi'+rnd+'">Chargement...</td></tr>').insertAfter($(this).parents('tr:first'));
dance:
for(var r=0; r<apiRoadmaps.length; r++) {
for(var c=0; c<apiRoadmaps[r].cards.length; c++) {
for(var i=0; i<apiRoadmaps[r].cards[c].pipeline.ideas.length; i++) {
if ($(this).text() == apiRoadmaps[r].cards[c].pipeline.ideas[i].title) {
var id = apiRoadmaps[r].cards[c].pipeline.ideas[i].id;
$.get('https://api.prodpad.com/v1/ideas/'+id+'?expand&apikey='+apiKey).then(function(json){
console.log(json);
var html = '<table>';
html += '<tr><th width="120">Creator :</th><th style="font-weight:normal">'+(json.creator?json.creator.display_name:'-')+'</th></tr>';
html += '<tr><th>Onwer :</th><th style="font-weight:normal">'+(json.owner?json.owner.display_name:'-')+'</th></tr>';
html += '<tr><th>Description :</th><th style="font-weight:normal">'+linkify(json.description)+'</th></tr>';
if (json.functional_spec) {
html += '<tr><th>Specifications :</th><th style="font-weight:normal">'+linkify(json.functional_spec)+'</th></tr>';
}
if (json.notes) {
html += '<tr><th>Notes :</th><th style="font-weight:normal">'+linkify(json.notes)+'</th></tr>';
}
if (json.comments) {
html += '<tr><th>Commentaires :</th><th style="font-weight:normal">';
for(var c=0; c<json.comments.length; c++) {
html += '<div style="margin-bottom:20px">Le <u>'+json.comments[c].created_at + '</u> par <strong>' + json.comments[c].created_by.display_name + '</strong> :<br/>' + linkify(json.comments[c].comment+'</div>');
}
html += '</th></tr>';
}
html += '</table>';
$('#pxi'+rnd).html(html);
}, function() {
$('#pxi'+rnd).html('Erreur ProdPad lors du chargement. <a href="/ideas/'+num+'">Voir le détail de de l\'idée</a>');
});
break dance;
}
}
}
}
}
});
};
setInterval(function(){
if ($('.roadmap-column-wrapper').length) {
if (!$('.pxload').length) {
$('.roadmap-main-section').append('<h1 class="pxload">Chargement de l\'interface qui déchire...</h1>');
}
if (!$('.pxroadmap').length) {
setTimeout(enhanceRoadmap, 1000);
}
}
}, 200);
})();