瀏覽代碼

small fixes

Markus-Rost 4 年之前
父節點
當前提交
187002adb8
共有 2 個文件被更改,包括 10 次插入5 次删除
  1. 9 4
      functions/parse_page.js
  2. 1 1
      functions/verify.js

+ 9 - 4
functions/parse_page.js

@@ -306,9 +306,14 @@ function parse_page(lang, msg, content, embed, wiki, reaction, {title, contentmo
 				if ( !section.length ) {
 					section = $('[id="' + toSection(fragment, false).replace( '#', '' ) + '"]');
 					newFragment = section.attr('id');
-					if ( section.is(':empty') ) section = section.parent();
-					if ( ['h1','h2','h3','h4','h5','h6'].includes( section.prev()[0]?.tagName ) ) {
-						section = section.prev();
+					if ( section.is(':empty') ) {
+						section = section.parent();
+						if ( ['h1','h2','h3','h4','h5','h6'].includes( section.prev()[0]?.tagName ) ) {
+							section = section.prev();
+							if ( section.children('span').first().attr('id') ) {
+								newFragment = section.children('span').first().attr('id');
+							}
+						}
 					}
 				}
 				if ( !section.length ) exactMatch = false;
@@ -346,7 +351,7 @@ function parse_page(lang, msg, content, embed, wiki, reaction, {title, contentmo
 					if ( name.length && value.length ) {
 						embed.spliceFields( 0, 0, {name, value} );
 						if ( newFragment ) {
-							embed.setURL( pagelink.replace( toSection(fragment), '#' + newFragment ) );
+							embed.setURL( pagelink.replace( toSection(fragment), toSection(newFragment) ) );
 							content = content.replace( '<' + pagelink + '>', '<' + embed.url + '>' );
 						}
 					}

+ 1 - 1
functions/verify.js

@@ -116,7 +116,7 @@ function verify(lang, channel, member, username, wiki, rows, old_username = '')
 				queryuser.postcount = ucbody.userData.posts;
 				if ( ucbody.userData.discordHandle ) discordname = escapeFormatting(ucbody.userData.discordHandle).replace( /^\s*([^@#:]{2,32}?)\s*#(\d{4,6})\s*$/u, '$1#$2' );
 				
-				if ( wiki.isGamepedia() || !discordname ) return got.get( wiki + 'api.php?action=profile&do=getPublicProfile&user_name=' + encodeURIComponent( username ) + '&format=json&cache=' + Date.now() ).then( presponse => {
+				if ( wiki.isGamepedia() || !discordname ) return got.get( ( wiki.isGamepedia() ? wiki : 'https://help.fandom.com/' ) + 'api.php?action=profile&do=getPublicProfile&user_name=' + encodeURIComponent( username ) + '&format=json&cache=' + Date.now() ).then( presponse => {
 					var pbody = presponse.body;
 					if ( presponse.statusCode !== 200 || !pbody || pbody.error || pbody.errormsg || !pbody.profile ) {
 						console.log( '- ' + presponse.statusCode + ': Error while getting the Discord tag: ' + ( pbody?.error?.info || pbody?.errormsg ) );