Fimfiction Chapter Themes API

An API for creating custom chapter themes on fimfiction

目前為 2014-10-19 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/5867/21854/Fimfiction%20Chapter%20Themes%20API.js

  1. // ==UserScript==
  2. // @name Fimfiction Chapter Themes API
  3. // @author Sollace
  4. // @namespace fimfiction-sollace
  5. // @version 1.0.1
  6. // @include http://www.fimfiction.net/*
  7. // @include https://www.fimfiction.net/*
  8. // @grant none
  9. // ==/UserScript==
  10. var ponyThemes = (function() {
  11. var data = {};
  12. function addGlobalStyle(css) {
  13. var style = document.createElement('style');
  14. style.type = 'text/css';
  15. style.innerHTML = css;
  16. if (document.head != null) {
  17. document.head.appendChild(style);
  18. } else {
  19. document.body.appendChild(style);
  20. }
  21. }
  22. function createStyleSet(styles) {
  23. var result = '';
  24. for (var i in styles) result += i + ': ' + styles[i].replace(/ \!important/g, '') + ' !important;';
  25. return result;
  26. }
  27. function ponyTheme(name, style) {
  28. this.Name = name.replace(/_/g, ' ');
  29. name = name.replace(/ /g, '_');
  30. this.option = '<option value="' + name + '">' + this.Name + '</option>';
  31. this.css = '';
  32. if (style['story']) this.css += '.content_format_' + name + ' a.story_name {' + createStyleSet(style.story) + '}';
  33. if (style['content']) this.css += '.content_format_' + name + ' {' + createStyleSet(style.content) + '}';
  34. if (style['p']) this.css += '.content_format_' + name + ' p {' + createStyleSet(style.p) + '}';
  35. if (style['pnth']) this.css += '.content_' + name + ' p:nth-child(' + style.pnth.n + ') {' + createStyleSet(style.pnth) + '}';
  36. }
  37. if ($('#format_colours').attr('apiInit') != '1') {
  38. $('#format_colours').attr('apiInit', '1');
  39. $(document).ready(function() {
  40. $('#format_colours').on('change', function() {
  41. unsafeWindow.LocalStorageSet( "format_colours_2", $("#format_colours").val());
  42. });
  43. });
  44. }
  45. return {
  46. apply: function() {
  47. var sheet = '';
  48. for (var i in data) {
  49. for (var j in data[i]) {
  50. sheet += data[i][j].css;
  51. if (!$('optgroup[label="' + i + '"]').length) {
  52. $('optgroup[label="Ponies"]').after('<optgroup label="' + i + '" />');
  53. }
  54. $('optgroup[label="' + i + '"]').append(data[i][j].option);
  55. }
  56. }
  57. addGlobalStyle(sheet);
  58. $('#format_colours').val(unsafeWindow.LocalStorageGet('format_colours_2', unsafeWindow.LocalStorageGet('format_colours', 'bow'))); unsafeWindow.UpdateColours();
  59. }, add: function(category, name, style) {
  60. if (!data[category]) data[category] = {};
  61. data[category][name] = new ponyTheme(name, style);
  62. return {one: category, two: name};
  63. }, remove: function(key) {
  64. data[key.one][key.two] = null;
  65. }
  66. }
  67. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址