-
Notifications
You must be signed in to change notification settings - Fork 3
/
InterfaceA.user.js
182 lines (146 loc) · 6.26 KB
/
InterfaceA.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// ==UserScript==
// @name Interface A
// @description Add-on for Drupal.org
// @icon https://github.com/albaloo/procid-client/blob/master/images/procid-icon.png
// @author Roshanak Zilouchian
// @version 1.2
// @grant none
// @include https://drupal.org/node/2262379*
// @include http://drupal.org/node/2262379*
// @include https://drupal.org/node/2262365*
// @include http://drupal.org/node/2262365*
// @include https://drupal.org/node/2258989*
// @include http://drupal.org/node/2258989*
// @include https://drupal.org/node/2258971*
// @include http://drupal.org/node/2258971*
// @include https://drupal.org/node/2250321*
// @include http://drupal.org/node/2250321*
// @include https://drupal.org/node/2250357*
// @include http://drupal.org/node/2250357*
// @include http://drupal.org/node/2214271*
// @include https://drupal.org/node/2214271*
// @include http://drupal.org/node/2035259*
// @include https://drupal.org/node/2035259*
// @include http://drupal.org/comment/*
// @include https://drupal.org/comment/*
// @match http://drupal.org/*
// @match https://drupal.org/*
// @include https://web.engr.illinois.edu/~rzilouc2/procid/example*
// ==/UserScript==
function load(url, onLoad, onError) {
var e = document.createElement("script");
e.setAttribute("src", url);
if (onLoad !== null) { e.addEventListener("load", onLoad); }
if (onError !== null) { e.addEventListener("error", onError); }
var body = document.getElementsByTagName('head')[0];
body.appendChild(e);
return e;
}
function execute(functionOrCode) {
if (typeof functionOrCode === "function") {
code = "(" + functionOrCode + ")();";
} else {
code = functionOrCode;
}
var e = document.createElement("script");
e.textContent = code;
var body = document.getElementsByTagName('head')[0];
body.appendChild(e);
return e;
}
function loadAndExecute(url, functionOrCode) {
load(url, function() { execute(functionOrCode); });
}
// the main function of this userscript
function main() {
head.js("//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js", "//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js", "//cdnjs.cloudflare.com/ajax/libs/d3/3.0.8/d3.min.js", function() {
console.log("begin");
var ABSOLUTEPATH = 'https://raw.github.com/albaloo/procid-client/master';
var CSSSERVERPATH = 'https://web.engr.illinois.edu/~rzilouc2/procid';
//var serverURL='http://0.0.0.0:3000/';
var serverURL = 'https://procid-lab-study-server.herokuapp.com/';
var currentUser = "";
var currentUserLink = "";
var setUpInterfaceA = function() {
//Check if this is an issue page
if (!$("#page").find("div [class='breadcrumb']").length)
return;
var path = window.location.pathname;
var issueLink;
if (path.indexOf("node") >= 0)
issueLink = window.location.pathname;
else
issueLink = $("link[rel='shortlink']").attr('href');
console.log("issueLink: " + issueLink)
addCSSToHeader();
//Check if the user has logged in Drupal
if (!$("#page").find('#project-issue-node-form').length){
//window.alert("Please Login to Drupal to view InterfaceA's features.");
$("<div id='dialog' style='padding:10px;' title='You are not Logged in'><p>Please Log in to Drupal to view Interface A's features: <a style='color: #0678be' href='https://drupal.org/user?destination="+issueLink.substr(1)+"'>Click to Log in</a></p></div>").dialog({
height: 120,
width: 350,
modal: true,
resizable:false,
});
return;
}
//find the currentUser
var currentUserInfo = $("#userinfo a").first().text();
currentUser = currentUserInfo.substr(13);
currentUserLink = "" + $($.find('li[class="dashboard last"] a')[0]).attr("href");
var linkIndex = currentUserLink.indexOf("/dashboard");
currentUserLink = currentUserLink.substring(0, linkIndex);
if (currentUser === "")
currentUser = "Anonymous";
console.log("username: " + currentUser + " link: " + currentUserLink);
//Program Starts From here
startInterfaceA();
};
var addCSSToHeader = function() {
var header = document.getElementsByTagName('head')[0];
var csslink = document.createElement('link');
csslink.setAttribute('href', CSSSERVERPATH + '/style-A.css');
csslink.setAttribute('rel', 'stylesheet');
csslink.setAttribute('type', 'text/css');
header.appendChild(csslink);
var csslink2 = document.createElement('link');
csslink2.setAttribute('href', '//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css');
csslink2.setAttribute('rel', 'stylesheet');
//csslink2.setAttribute('type', 'text/css');
header.appendChild(csslink2);
};
var startInterfaceA = function() {
//Add the header
var header = createHeader();
var pageWrapper = document.createElement('div');
pageWrapper.setAttribute('id', 'procid-outer-page-wrapper');
$("#page").wrap(pageWrapper);
$("#page" ).before(header);
//var outerPageWrapper = document.createElement('div');
//outerPageWrapper.setAttribute('id', 'procid-outer-page-wrapper');
//outerPageWrapper.appendChild(header);
//$("#procid-page-wrapper").wrap(outerPageWrapper);
//pageWrapper.insertBefore(header, pageWrapper.firstChild);
};
var createHeader = function() {
var header = document.createElement('div');
header.setAttribute('id', 'procid-left-panel-header');
header.innerHTML = ' ';
//Menu
var procidMenu = document.createElement('ul');
procidMenu.setAttribute('id', 'procid-menus');
header.appendChild(procidMenu);
$("#procid-menus").css("border-image", "url(" + ABSOLUTEPATH + "/images/top-line.png) 13 2 round");
//Procid Label
var procidLabel = document.createElement('div');
procidLabel.setAttribute('id', 'procid-label');
procidLabel.innerHTML = "Interface A"
//$(procidLabel).css('background-image', "url(" + ABSOLUTEPATH + "/images/sprites-main-page.png)");
procidMenu.appendChild(procidLabel);
return header;
};
setUpInterfaceA();
console.log("done");
});
}
loadAndExecute("//raw.github.com/headjs/headjs/v0.99/dist/head.min.js", main);