Guest User

Untitled

a guest
Jun 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. // プロジェクトタイトルでタイトルなどの色変更
  2. //
  3. // Path pattern: /projects/
  4. // Type: JavaScript
  5.  
  6. function changeColor(xpath, color) {
  7. var elm = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  8. elm.singleNodeValue.style.backgroundColor = color
  9. }
  10.  
  11. var colors = ['#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#87c34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b'];
  12.  
  13. function getIndex(seed) {
  14. var work = 0;
  15. for (var i = 0; i < seed.length; i++) {
  16. work += seed.charCodeAt(i);
  17. }
  18. return work % colors.length;
  19. }
  20.  
  21. $(function () {
  22. var titleElm = document.evaluate('//*[@id="header"]/h1', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
  23.  
  24. var title = titleElm.singleNodeValue.textContent;
  25. var primary = getIndex(title);
  26. var secondary = (primary + title.length) % colors.length;
  27.  
  28. if (primary === secondary) {
  29. secondary = (secondary + 1) % colors.length;
  30. }
  31.  
  32. changeColor('//*[@id="header"]', colors[primary]);
  33. changeColor('//*[@id="top-menu"]', colors[secondary]);
  34. })
Add Comment
Please, Sign In to add comment