Last active
May 19, 2017 08:25
-
-
Save callmewhy/c620aad518a12e4ef335506dd742d57b to your computer and use it in GitHub Desktop.
make Phabricator great again
This file contains 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 Phabricator | |
// @namespace http://advance.ai/ | |
// @version 0.1 | |
// @description make phabricator great again | |
// @author callmewhy | |
// @match https://go.advance.ai/project/view/* | |
// @require https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js | |
// @grant GM_addStyle | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
const url = 'https://go.advance.ai'; | |
GM_addStyle(` | |
.phui-oi-table-row ul { | |
margin: 0 10px; | |
font-size: 10px; | |
} | |
.phui-oi-table-row ul.subtask { | |
list-style-type: circle; | |
list-style-position: inside; | |
} | |
.phui-oi-table-row ul.subtask li.done { | |
list-style-type: disc; | |
} | |
`); | |
$(document).ready(function(){ | |
const items = $('li.phui-workcard'); | |
for (let item of items) { | |
const taskId = $(item).find('span.phui-oi-objname').text(); | |
// get task info by task id | |
$.post(`${url}/api/maniphest.info`, { | |
'params[task_id]': taskId.slice(1), | |
'output': 'json', | |
'__csrf__': $('form input[name="__csrf__"]').val(), | |
'form': 1, | |
}, function(data) { | |
const result = data.result; | |
const dependsOnTaskPHIDs = result.dependsOnTaskPHIDs || []; | |
console.log(dependsOnTaskPHIDs); | |
// get all subtasks' title | |
$.post(`${url}/api/maniphest.query`, { | |
'params[phids]': JSON.stringify(dependsOnTaskPHIDs), | |
'output': 'json', | |
'__csrf__': $('form input[name="__csrf__"]').val(), | |
'form': 1, | |
}, function(data) { | |
const result = data.result; | |
console.log(result); | |
const titles = dependsOnTaskPHIDs.map(phid => task = ` | |
<li class="subtask ${result[phid].isClosed ? 'done' : ''}"> | |
<a href="${result[phid].uri}">${result[phid].title}</a> | |
</li> | |
`); | |
const insertDOM = `<div class="phui-oi-table-row"><ul class="subtask">${titles.join('')}</ul></div>`; | |
$(item).find('.phui-oi-table').append(insertDOM); | |
}); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment