Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // プロジェクトタイトルでタイトルなどの色変更
- //
- // Path pattern: /projects/
- // Type: JavaScript
- function changeColor(xpath, color) {
- var elm = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
- elm.singleNodeValue.style.backgroundColor = color
- }
- var colors = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#87c34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b'];
- function getIndex(seed) {
- var work = 0;
- for (var i = 0; i < seed.length; i++) {
- work += seed.charCodeAt(i);
- }
- return work % colors.length;
- }
- $(function () {
- var titleElm = document.evaluate('//*[@id="header"]/h1', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
- var title = titleElm.singleNodeValue.textContent;
- var primary = getIndex(title);
- var secondary = (primary + title.length) % colors.length;
- if (primary === secondary) {
- secondary = (secondary + 1) % colors.length;
- }
- changeColor('//*[@id="header"]', colors[primary]);
- changeColor('//*[@id="top-menu"]', colors[secondary]);
- })
Add Comment
Please, Sign In to add comment